mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 09:19:22 +02:00
feature: Cache::remember($key, $ttl, $callback) + example usage
This commit is contained in:
parent
c1096415aa
commit
0002543cca
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -101,14 +101,15 @@ if(isset($_GET['image']))
|
||||
return;
|
||||
}
|
||||
|
||||
$images =
|
||||
$db->query('SELECT `id`, `comment`, `image`, `author`, `thumb`' .
|
||||
$images = Cache::remember('gallery_' . ($canEdit ? '1' : '0'), 60, function () use ($db, $canEdit) {
|
||||
return $db->query('SELECT `id`, `comment`, `image`, `author`, `thumb`' .
|
||||
($canEdit ? ', `hidden`, `ordering`' : '') .
|
||||
' FROM `' . TABLE_PREFIX . 'gallery`' .
|
||||
(!$canEdit ? ' WHERE `hidden` != 1' : '') .
|
||||
' ORDER BY `ordering`;');
|
||||
' ORDER BY `ordering`;')->fetchAll(PDO::FETCH_ASSOC);
|
||||
});
|
||||
|
||||
$last = $images->rowCount();
|
||||
$last = count($images);
|
||||
if(!$last)
|
||||
{
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user