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