mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-27 17:59:22 +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
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function enabled() {return false;}
|
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