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' );
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
*/
}
}
- Cache::set("probe_url:".$mode.":".$url,serialize($result));
+ Cache::set("probe_url:".$mode.":".$url,serialize($result), CACHE_DAY);
return $result;
}
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));
}
}
"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(
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){
$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);
if ($txt[0]!="{") $txt='{"type":"error"}';
//save in cache
- Cache::set($a->videowidth . $embedurl,$txt);
+ Cache::set($a->videowidth . $embedurl,$txt, CACHE_DAY);
}
$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;
}
<?php
-define( 'UPDATE_VERSION' , 1187 );
+define( 'UPDATE_VERSION' , 1188 );
/**
*