public function get($key, &$token = null)
{
$value = $this->local->get($key, $token);
// short-circuit reading from real cache if we have an uncommitted flush
if ($this->suspend && $token === null) {
// flush hasn't been committed yet, don't read from real cache!
return false;
}
if ($value === false) {
if ($this->local->expired($key)) {
/*
* Item used to exist in local cache, but is now expired. This
* is used when values are to be deleted: we don't want to reach
* out to real storage because that would respond with the not-
* yet-deleted value.
*/
return false;
}
// unknown in local cache = fetch from source cache
$value = $this->cache->get($key, $token);
}
// no value = quit early, don't generate a useless token
if ($value === false) {
return false;
}
/*
* $token will be unreliable to the deferred updates so generate
* a custom one and keep the associated value around.
* Read more details in PHPDoc for function cas().
* uniqid is ok here. Doesn't really have to be unique across
* servers, just has to be unique every time it's called in this
* one particular request - which it is.
*/
$token = uniqid();
$this->tokens[$token] = serialize($value);
return $value;
}