MatthiasMullie\Scrapbook\Buffered\Utils\Buffer::expired PHP Метод

expired() публичный Метод

Because our local buffer is also just a real cache, expired items will just return nothing, which will lead us to believe no such item exists in that local cache, and we'll reach out to the real cache (where the value may not yet have been expired because that may have been part of an uncommitted write) So we'll want to know when a value is in local cache, but expired!
public expired ( string $key ) : boolean
$key string
Результат boolean
    public function expired($key)
    {
        if ($this->get($key) !== false) {
            // returned a value, clearly not yet expired
            return false;
        }
        // a known item, not returned by get, is expired
        return array_key_exists($key, $this->items);
    }

Usage Example

Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function getMulti(array $keys, array &$tokens = null)
 {
     // retrieve all that we can from local cache
     $values = $this->local->getMulti($keys);
     $tokens = array();
     // short-circuit reading from real cache if we have an uncommitted flush
     if (!$this->suspend) {
         // figure out which missing key we need to get from real cache
         $keys = array_diff($keys, array_keys($values));
         foreach ($keys as $i => $key) {
             // don't reach out to real cache for keys that are about to be gone
             if ($this->local->expired($key)) {
                 unset($keys[$i]);
             }
         }
         // fetch missing values from real cache
         if ($keys) {
             $missing = $this->cache->getMulti($keys);
             $values += $missing;
         }
     }
     // any tokens we get will be unreliable, so generate some replacements
     // (more elaborate explanation in get())
     foreach ($values as $key => $value) {
         $token = uniqid();
         $tokens[$key] = $token;
         $this->tokens[$token] = serialize($value);
     }
     return $values;
 }