Gdn_Cache::localSet PHP Method

localSet() protected method

protected localSet ( $key, $value = null )
    protected function localSet($key, $value = null)
    {
        if (!$this->hasFeature(Gdn_Cache::FEATURE_LOCAL)) {
            return;
        }
        if (!is_array($key)) {
            $key = array($key => $value);
        }
        self::$localCache = array_merge(self::$localCache, $key);
    }

Usage Example

コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function decrement($key, $amount = 1, $options = array())
 {
     if (!$this->online()) {
         return Gdn_Cache::CACHEOP_FAILURE;
     }
     $finalOptions = array_merge($this->StoreDefaults, $options);
     $initial = val(Gdn_Cache::FEATURE_INITIAL, $finalOptions, null);
     $expiry = val(Gdn_Cache::FEATURE_EXPIRY, $finalOptions, null);
     $requireBinary = $initial || $expiry;
     $initial = !is_null($initial) ? $initial : 0;
     $expiry = !is_null($expiry) ? $expiry : 0;
     $tryBinary = $this->option(Memcached::OPT_BINARY_PROTOCOL, false) & $requireBinary;
     $realKey = $this->makeKey($key, $finalOptions);
     switch ($tryBinary) {
         case false:
             $decremented = $this->memcache->decrement($realKey, $amount);
             if (is_null($decremented) && $initial) {
                 $decremented = $this->memcache->set($realKey, $initial);
                 if ($decremented) {
                     $decremented = $initial;
                 }
             }
             break;
         case true:
             $decremented = $this->memcache->decrement($realKey, $amount, $initial, $expiry);
             break;
     }
     // Check if things went ok
     $ok = $this->lastAction($realKey);
     if (!$ok) {
         return Gdn_Cache::CACHEOP_FAILURE;
     }
     if ($decremented !== false) {
         Gdn_Cache::localSet($realKey, $decremented);
         return $decremented;
     }
     return Gdn_Cache::CACHEOP_FAILURE;
 }