/** * In addition to all writes being stored to $local, we'll also * keep get() values around ;). * * {@inheritdoc} */ public function get($key, &$token = null) { $value = $this->transaction->get($key, $token); // only store if we managed to retrieve a value (valid token) and it's // not already in cache (or we may mess up tokens) if ($value !== false && $this->local->get($key, $localToken) === false && $localToken === null) { $this->local->set($key, $value); } return $value; }
/** * {@inheritdoc} */ 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; }