]> git.mxchange.org Git - friendica.git/commitdiff
Now you can define the duration of the cache entries.
authorMichael Vogel <icarus@dabo.de>
Mon, 24 Aug 2015 15:24:14 +0000 (17:24 +0200)
committerMichael Vogel <icarus@dabo.de>
Mon, 24 Aug 2015 15:24:14 +0000 (17:24 +0200)
boot.php
include/Scrape.php
include/cache.php
include/dbstructure.php
include/discover_poco.php
include/items.php
include/oembed.php
mod/parse_url.php
update.php

index 7fb4591411c99fdb44f3373800e21ebacdf9777c..7451891fef1805571301f14ab27d3749f240455e 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -19,7 +19,7 @@ define ( 'FRIENDICA_PLATFORM',     'Friendica');
 define ( 'FRIENDICA_CODENAME',     'Lily of the valley');
 define ( 'FRIENDICA_VERSION',      '3.4.1' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1187      );
+define ( 'DB_UPDATE_VERSION',      1188      );
 define ( 'EOL',                    "<br />\r\n"     );
 define ( 'ATOM_TIME',              'Y-m-d\TH:i:s\Z' );
 
@@ -84,6 +84,15 @@ define ( 'LOGGER_DEBUG',           2 );
 define ( 'LOGGER_DATA',            3 );
 define ( 'LOGGER_ALL',             4 );
 
+/**
+ * cache levels
+ */
+
+define ( 'CACHE_MONTH',            0 );
+define ( 'CACHE_WEEK',             1 );
+define ( 'CACHE_DAY',              2 );
+define ( 'CACHE_HOUR',             3 );
+
 /**
  * registration policies
  */
index 83c099769d456d851175ec9dcffba9f2e37a7c5f..a2bf5ee0aa25ae18f8ace6313af302b50b1aa629 100644 (file)
@@ -819,7 +819,7 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
                }
        }
 
-       Cache::set("probe_url:".$mode.":".$url,serialize($result));
+       Cache::set("probe_url:".$mode.":".$url,serialize($result), CACHE_DAY);
 
        return $result;
 }
index 3a18fe2a5a45b237a3a3b605d3a79a082786bbaf..d0b0dfafda9c4fc011102bf6a2fa0cd3cbc00d1b 100644 (file)
@@ -5,33 +5,25 @@
 
        class Cache {
                public static function get($key) {
-                       /*if (function_exists("apc_fetch") AND function_exists("apc_exists"))
-                               if (apc_exists($key))
-                                       return(apc_fetch($key));*/
 
                        $r = q("SELECT `v` FROM `cache` WHERE `k`='%s' limit 1",
                                dbesc($key)
                        );
 
-                       if (count($r)) {
-                               /*if (function_exists("apc_store"))
-                                       apc_store($key, $r[0]['v'], 600);*/
-
+                       if (count($r))
                                return $r[0]['v'];
-                       }
+
                        return null;
                }
 
-               public static function set($key,$value) {
+               public static function set($key,$value, $duration = CACHE_MONTH) {
 
-                       q("REPLACE INTO `cache` (`k`,`v`,`updated`) VALUES ('%s','%s','%s')",
+                       q("REPLACE INTO `cache` (`k`,`v`,`expire_mode`,`updated`) VALUES ('%s','%s',%d,'%s')",
                                        dbesc($key),
                                        dbesc($value),
+                                       intval($duration),
                                        dbesc(datetime_convert()));
 
-                       /*if (function_exists("apc_store"))
-                               apc_store($key, $value, 600);*/
-
                }
 
 
 
 
                public static function clear(){
-                       q("DELETE FROM `cache` WHERE `updated` < '%s'",
-                               dbesc(datetime_convert('UTC','UTC',"now - 30 days")));
+                       q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
+                               dbesc(datetime_convert('UTC','UTC',"now - 30 days")), intval(CACHE_MONTH));
+
+                       q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
+                               dbesc(datetime_convert('UTC','UTC',"now - 7 days")), intval(CACHE_WEEK));
+
+                       q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
+                               dbesc(datetime_convert('UTC','UTC',"now - 1 days")), intval(CACHE_DAY));
+
+                       q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
+                               dbesc(datetime_convert('UTC','UTC',"now - 1 hours")), intval(CACHE_HOUR));
                }
 
        }
index 2370b01becc365b97e64fd5f1fbd6b31f6a65c4c..2b1ee84fdac90b4a975bf411ae21ed47c9683fd0 100644 (file)
@@ -364,6 +364,7 @@ function db_definition() {
                        "fields" => array(
                                        "k" => array("type" => "varchar(255)", "not null" => "1", "primary" => "1"),
                                        "v" => array("type" => "text", "not null" => "1"),
+                                       "expire_mode" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
                                        "updated" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
                                        ),
                        "indexes" => array(
index 4a17b49279aa952fcf1f43c1df60e5fecc7879e2..79958a8849a4235b7a53156cc5c2fdddd26de046 100644 (file)
@@ -183,7 +183,7 @@ function discover_directory($search) {
                                poco_check($data["url"], $data["name"], $data["network"], $data["photo"], "", "", "", $jj->tags, $data["addr"], "", 0);
                        }
                }
-       Cache::set("dirsearch:".$search, time());
+       Cache::set("dirsearch:".$search, time(), CACHE_DAY);
 }
 
 if (array_search(__file__,get_included_files())===0){
index a2b2a0197b8aaaf5e80ac2ad777b3c50151c7e6a..f15e2a1fc5119580848f3024aa3dbf3917e19fa6 100644 (file)
@@ -969,7 +969,7 @@ function query_page_info($url, $no_photos = false, $photo = "", $keywords = fals
        $data = Cache::get("parse_url:".$url);
        if (is_null($data)){
                $data = parseurl_getsiteinfo($url, true);
-               Cache::set("parse_url:".$url,serialize($data));
+               Cache::set("parse_url:".$url,serialize($data), CACHE_DAY);
        } else
                $data = unserialize($data);
 
index b32cb512be54a90d242f6cf9d15cbeebd8934df0..aec92bfa04ee05498e8baa8b5124728a9183ddf1 100755 (executable)
@@ -73,7 +73,7 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
                if ($txt[0]!="{") $txt='{"type":"error"}';
 
                //save in cache
-               Cache::set($a->videowidth . $embedurl,$txt);
+               Cache::set($a->videowidth . $embedurl,$txt, CACHE_DAY);
 
        }
 
index 50c6a15b0e7c7837326edd43b468334efe922d00..97eebb89ab630ae2b9aa5a8417733baaa5fb4d43 100644 (file)
@@ -60,7 +60,7 @@ function parseurl_getsiteinfo_cached($url, $no_guessing = false, $do_oembed = tr
 
        $data = parseurl_getsiteinfo($url, $no_guessing, $do_oembed);
 
-       Cache::set("parse_url:".$no_guessing.":".$do_oembed.":".$url,serialize($data));
+       Cache::set("parse_url:".$no_guessing.":".$do_oembed.":".$url,serialize($data), CACHE_DAY);
 
        return $data;
 }
index a2c86740284081df3cfe0aea89c6229f41f5652f..761da7273d5d94da645a528517a6eb7e0c62de75 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-define( 'UPDATE_VERSION' , 1187 );
+define( 'UPDATE_VERSION' , 1188 );
 
 /**
  *