if (empty($prefix)) {
$where = ['`expires` >= ?', DateTimeFormat::utcNow()];
} else {
- $where = ['`expires` >= ? AND k LIKE CONCAT(?, \'%\')', DateTimeFormat::utcNow(), $prefix];
+ $where = ['`expires` >= ? AND `k` LIKE CONCAT(?, \'%\')', DateTimeFormat::utcNow(), $prefix];
}
$stmt = DBA::select('cache', ['k'], $where);
- $list = [];
+ $keys = [];
while ($key = DBA::fetch($stmt)) {
- array_push($list, $key['k']);
+ array_push($keys, $key['k']);
}
DBA::close($stmt);
- return $list;
+ return $keys;
}
/**
*/
public function get($key)
{
- $cache = DBA::selectFirst('cache', ['v'], ['`k` = ? AND `expires` >= ?', $key, DateTimeFormat::utcNow()]);
+ $cache = DBA::selectFirst('cache', ['v'], ['`k` = ? AND (`expires` >= ? OR `expires` = -1)', $key, DateTimeFormat::utcNow()]);
if (DBA::isResult($cache)) {
$cached = $cache['v'];
*/
public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
{
- $fields = [
- 'v' => serialize($value),
- 'expires' => DateTimeFormat::utc('now + ' . $ttl . 'seconds'),
- 'updated' => DateTimeFormat::utcNow()
- ];
+ if ($ttl > 0) {
+ $fields = [
+ 'v' => serialize($value),
+ 'expires' => DateTimeFormat::utc('now + ' . $ttl . 'seconds'),
+ 'updated' => DateTimeFormat::utcNow()
+ ];
+ } else {
+ $fields = [
+ 'v' => serialize($value),
+ 'expires' => -1,
+ 'updated' => DateTimeFormat::utcNow()
+ ];
+ }
return DBA::update('cache', $fields, ['k' => $key], true);
}