The memory-part can easily be handled by MemoryStore. There's just 1 gotcha: when an item is to be deleted (but not yet committed), it needs to be deleted from the MemoryStore too, but we need to be able to make a distinction between "this is deleted" and "this value is not known in this memory cache, fall back to real cache". This is where this class comes in to play: we'll add an additional "expired" method, which allows BufferedStore to just expire the keys that are supposed to be deleted (instead of deleting them) - then we can keep track of when a key is just not known, or known-but-deleted (=expired)
Author: Matthias Mullie (scrapbook@mullie.eu)
Inheritance: extends MatthiasMullie\Scrapbook\Adapters\MemoryStore
Esempio n. 1
0
 /**
  * In addition to all writes being stored to $local, we'll also
  * keep get() values around ;).
  *
  * {@inheritdoc}
  */
 public function getMulti(array $keys, array &$tokens = null)
 {
     $values = $this->transaction->getMulti($keys, $tokens);
     $missing = array_diff_key($values, $this->local->getMulti($keys));
     if (!empty($missing)) {
         $this->local->setMulti($missing);
     }
     return $values;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function flush()
 {
     $success = $this->local->flush();
     if ($success === false) {
         return false;
     }
     // clear all buffered writes, flush wipes them out anyway
     $this->clear();
     // make sure that reads, from now on until commit, don't read from cache
     $this->suspend = true;
     $this->defer->flush();
     return true;
 }