From 901785663edc7045c66d9393432a18bb376436bb Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 25 Nov 2019 21:50:02 +0100 Subject: Fix once cached embedded content is used and stored forever --- Zotlabs/Lib/Cache.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'Zotlabs/Lib/Cache.php') diff --git a/Zotlabs/Lib/Cache.php b/Zotlabs/Lib/Cache.php index cea075659..878201a42 100644 --- a/Zotlabs/Lib/Cache.php +++ b/Zotlabs/Lib/Cache.php @@ -11,8 +11,10 @@ class Cache { $hash = hash('whirlpool',$key); - $r = q("SELECT v FROM cache WHERE k = '%s' limit 1", - dbesc($hash) + $r = q("SELECT v FROM cache WHERE k = '%s' AND updated > %s - INTERVAL %s LIMIT 1", + dbesc($hash), + db_utcnow(), + db_quoteinterval(get_config('system','object_cache_days', '30') . ' DAY') ); if ($r) @@ -40,12 +42,5 @@ class Cache { dbesc(datetime_convert())); } } - - - public static function clear() { - q("DELETE FROM cache WHERE updated < '%s'", - dbesc(datetime_convert('UTC','UTC',"now - 30 days"))); - } - } -- cgit v1.2.3 From 41ce2da080d72dbfd2c47a3973fe3c43672adb4d Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sun, 5 Jan 2020 11:49:36 +0100 Subject: Add age choice on cached item retrieve --- Zotlabs/Lib/Cache.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib/Cache.php') diff --git a/Zotlabs/Lib/Cache.php b/Zotlabs/Lib/Cache.php index 878201a42..bb7bbbff0 100644 --- a/Zotlabs/Lib/Cache.php +++ b/Zotlabs/Lib/Cache.php @@ -7,14 +7,23 @@ namespace Zotlabs\Lib; */ class Cache { - public static function get($key) { + + /** + * @brief Returns cached content + * + * @param string $key + * @param string $age in SQL format, default is '30 DAY' + * @return string + * / + + public static function get($key, $age = '') { $hash = hash('whirlpool',$key); $r = q("SELECT v FROM cache WHERE k = '%s' AND updated > %s - INTERVAL %s LIMIT 1", dbesc($hash), db_utcnow(), - db_quoteinterval(get_config('system','object_cache_days', '30') . ' DAY') + db_quoteinterval(($age ? $age : get_config('system','object_cache_days', '30') . ' DAY')) ); if ($r) -- cgit v1.2.3 From 908875a052ac76e24af74fc714b350c217de42b4 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 6 Jan 2020 20:40:18 +0100 Subject: Update Cache.php --- Zotlabs/Lib/Cache.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Zotlabs/Lib/Cache.php') diff --git a/Zotlabs/Lib/Cache.php b/Zotlabs/Lib/Cache.php index bb7bbbff0..a5052a183 100644 --- a/Zotlabs/Lib/Cache.php +++ b/Zotlabs/Lib/Cache.php @@ -14,7 +14,7 @@ class Cache { * @param string $key * @param string $age in SQL format, default is '30 DAY' * @return string - * / + */ public static function get($key, $age = '') { @@ -52,4 +52,3 @@ class Cache { } } } - -- cgit v1.2.3