7 public static function get($key) {
9 $r = q("SELECT `v` FROM `cache` WHERE `k`='%s' limit 1",
19 public static function set($key,$value, $duration = CACHE_MONTH) {
21 q("REPLACE INTO `cache` (`k`,`v`,`expire_mode`,`updated`) VALUES ('%s','%s',%d,'%s')",
25 dbesc(datetime_convert()));
32 * Leaving this legacy code temporaily to see how REPLACE fares
33 * as opposed to non-atomic checks when faced with fast moving key duplication.
34 * As a MySQL extension it isn't portable, but we're not yet very portable.
38 * $r = q("SELECT * FROM `cache` WHERE `k`='%s' limit 1",
42 * q("UPDATE `cache` SET `v` = '%s', `updated = '%s' WHERE `k` = '%s'",
44 * dbesc(datetime_convert()),
48 * q("INSERT INTO `cache` (`k`,`v`,`updated`) VALUES ('%s','%s','%s')",
51 * dbesc(datetime_convert()));
57 public static function clear(){
58 q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
59 dbesc(datetime_convert('UTC','UTC',"now - 30 days")), intval(CACHE_MONTH));
61 q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
62 dbesc(datetime_convert('UTC','UTC',"now - 7 days")), intval(CACHE_WEEK));
64 q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
65 dbesc(datetime_convert('UTC','UTC',"now - 1 days")), intval(CACHE_DAY));
67 q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
68 dbesc(datetime_convert('UTC','UTC',"now - 1 hours")), intval(CACHE_HOUR));