mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
New function Cache::remember($key, $ttl, $callback)
This commit is contained in:
parent
f851fa3845
commit
21258313ef
@ -110,4 +110,21 @@ class Cache
|
||||
* @return bool
|
||||
*/
|
||||
public function enabled() {return false;}
|
||||
|
||||
public static function remember($key, $ttl, $callback)
|
||||
{
|
||||
$cache = self::getInstance();
|
||||
if(!$cache->enabled()) {
|
||||
return $callback();
|
||||
}
|
||||
|
||||
$value = null;
|
||||
if ($cache->fetch($key, $value)) {
|
||||
return unserialize($value);
|
||||
}
|
||||
|
||||
$value = $callback();
|
||||
$cache->set($key, serialize($value),$ttl);
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user