MatthiasMullie\Scrapbook\KeyValueStore::getMulti PHP Method

getMulti() public method

Return value will be an associative array in [key => value] format. Keys missing in cache will be omitted from the array. Optionally, an 2nd variable can be passed to this function. It will be filled with values that can be used for cas(), in an associative array in [key => token] format. Keys missing in cache will be omitted from the array. getMulti is preferred over multiple individual get operations as you'll get them all in 1 request.
public getMulti ( array $keys, array &$tokens = null ) : mixed[]
$keys array
$tokens array Will be filled with the CAS tokens, in [key => token] format
return mixed[] [key => value]
    public function getMulti(array $keys, array &$tokens = null);

Usage Example

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;
 }
All Usage Examples Of MatthiasMullie\Scrapbook\KeyValueStore::getMulti