Example #1
0
 /**
  * Sets the value for this key only if the value hasn't changed in the cache
  * since it was originally pulled
  *
  * @param \r8\Cache\Result $result A result object that was returned by
  *      the getForUpdate method
  * @param mixed $value The value to set
  * @param Integer $expire The lifespan of this cache value, in seconds
  * @return \r8\iface\Cache Returns a self reference
  */
 public function setIfSame(\r8\Cache\Result $result, $value, $expire = 0)
 {
     if (!$this->cache instanceof \r8\iface\Cache\Updatable) {
         throw new \r8\Exception\Data($this->cache, 'Inner Cache', 'Must be an instance of \\r8\\iface\\Cache\\Updatable');
     }
     $this->cache->setIfSame(new \r8\Cache\Result($this->cache, $this->modifyKey($result->getKey()), $result->getHash(), $result->getValue()), $value, $expire);
     return $this;
 }
Example #2
0
 /**
  * Sets the value for this key only if the value hasn't changed in the cache
  * since it was originally pulled
  *
  * @param \r8\Cache\Result $result A result object that was returned by
  *      the getForUpdate method
  * @param mixed $value The value to set
  * @param Integer $expire The lifespan of this cache value, in seconds
  * @return \r8\iface\Cache Returns a self reference
  */
 public function setIfSame(\r8\Cache\Result $result, $value, $expire = 0)
 {
     $currentValue = $this->get($result->getKey());
     if (sha1(serialize($currentValue)) == $result->getHash()) {
         $this->set($result->getKey(), $value, $expire);
     }
     return $this;
 }
Example #3
0
 /**
  * Sets the value for this key only if the value hasn't changed in the cache
  * since it was originally pulled
  *
  * @param \r8\Cache\Result $result A result object that was returned by
  *      the getForUpdate method
  * @param mixed $value The value to set
  * @param Integer $expire The lifespan of this cache value, in seconds
  * @return \r8\iface\Cache Returns a self reference
  */
 public function setIfSame(\r8\Cache\Result $result, $value, $expire = 0)
 {
     $this->memcached->cas($result->getHash(), $this->prepareKey($result->getKey()), $value, $this->prepareExpire($expire));
     $this->handleErrors();
     return $this;
 }