public function touch($key, $expire)
{
$ttl = $this->ttl($expire);
// shortcut - expiring is similar to deleting, but the former has no
// 1-operation equivalent
if ($ttl < 0) {
return $this->delete($key);
}
// get existing TTL & quit early if it's that one already
$iterator = $this->APCuIterator('/^' . preg_quote($key, '/') . '$/', \APC_ITER_VALUE | \APC_ITER_TTL, 1, \APC_LIST_ACTIVE);
$current = $iterator->current();
if (!$current) {
// doesn't exist
return false;
}
if ($current['ttl'] === $ttl) {
// that's the TTL already, no need to reset it
return true;
}
// generate CAS token to safely CAS existing value with new TTL
$value = $current['value'];
$token = serialize($value);
return $this->cas($token, $key, $value, $ttl);
}