MatthiasMullie\Scrapbook\KeyValueStore::get PHP Method

get() public method

Optionally, an 2nd variable can be passed to this function. It will be filled with a value that can be used for cas()
public get ( string $key, mixed &$token = null ) : mixed | boolean
$key string
$token mixed Will be filled with the CAS token
return mixed | boolean Value, or false on failure
    public function get($key, &$token = null);

Usage Example

Example #1
0
 /**
  * Roll the cache back to pre-transaction state by comparing the current
  * cache values with what we planned to set them to.
  *
  * @param array $old
  * @param array $new
  */
 protected function rollback(array $old, array $new)
 {
     foreach ($old as $key => $value) {
         $current = $this->cache->get($key, $token);
         /*
          * If the value right now equals the one we planned to write, it
          * should be restored to what it was before. If it's yet something
          * else, another process must've stored it and we should leave it
          * alone.
          */
         if ($current === $new) {
             /*
              * CAS the rollback. If it fails, that means another process
              * has stored in the meantime and we can just leave it alone.
              * Note that we can't know the original expiration time!
              */
             $this->cas($token, $key, $value, 0);
         }
     }
     $this->clear();
 }
All Usage Examples Of MatthiasMullie\Scrapbook\KeyValueStore::get