示例#1
0
 /**
  * Reads in known/config servers and adds them to the instance.
  *
  * This method is called when the cache object is invoked by the framework
  * automatically, and needs to configure itself from the values in the global
  * config file.
  */
 public function Autorun()
 {
     $Servers = Gdn_Cache::ActiveStore('memcached');
     if (!is_array($Servers)) {
         $Servers = explode(',', $Servers);
     }
     // No servers, cache temporarily offline
     if (!sizeof($Servers)) {
         SaveToConfig('Cache.Enabled', false, false);
         return false;
     }
     // Persistent, and already have servers. Shortcircuit adding.
     if ($this->Config(Gdn_Cache::CONTAINER_PERSISTENT) && count($this->servers())) {
         return true;
     }
     $Keys = array(Gdn_Cache::CONTAINER_LOCATION, Gdn_Cache::CONTAINER_PERSISTENT, Gdn_Cache::CONTAINER_WEIGHT, Gdn_Cache::CONTAINER_TIMEOUT, Gdn_Cache::CONTAINER_ONLINE, Gdn_Cache::CONTAINER_CALLBACK);
     foreach ($Servers as $CacheServer) {
         $CacheServer = explode(' ', $CacheServer);
         $CacheServer = array_pad($CacheServer, count($Keys), NULL);
         $CacheServer = array_combine($Keys, $CacheServer);
         foreach ($Keys as $KeyName) {
             $Value = val($KeyName, $CacheServer, NULL);
             if (is_null($Value)) {
                 unset($CacheServer[$KeyName]);
             }
         }
         $this->AddContainer($CacheServer);
     }
 }
 /**
 * Reads in known/config servers and adds them to the instance.
 * 
 * This method is called when the cache object is invoked by the framework 
 * automatically, and needs to configure itself from the values in the global
 * config file.
 */
 public function Autorun() {
    $Servers = Gdn_Cache::ActiveStore('memcache');
    if (!is_array($Servers)) 
       $Servers = explode(',',$Servers);
       
    $Keys = array(
       Gdn_Cache::CONTAINER_LOCATION,
       Gdn_Cache::CONTAINER_PERSISTENT,
       Gdn_Cache::CONTAINER_WEIGHT,
       Gdn_Cache::CONTAINER_TIMEOUT,
       Gdn_Cache::CONTAINER_ONLINE,
       Gdn_Cache::CONTAINER_CALLBACK
    );
    foreach ($Servers as $CacheServer) {
       $CacheServer = explode(' ',$CacheServer);
       $CacheServer = array_pad($CacheServer,count($Keys),NULL);
       $CacheServer = array_combine($Keys,$CacheServer);
       
       foreach ($Keys as $KeyName) {
          $Value = GetValue($KeyName, $CacheServer, NULL);
          if (is_null($Value))
             unset($CacheServer[$KeyName]);
       }
       
       $this->AddContainer($CacheServer);
    }
 }
示例#3
0
 /**
  * Register a temporary server connection failure
  *
  * This method will attempt to temporarily excise the offending server from
  * the connect roster for a period of time.
  *
  * @param string $server
  */
 public function Fail($server)
 {
     // Use APC?
     $apc = false;
     if (C('Garden.Apc', false) && function_exists('apc_fetch')) {
         $apc = true;
     }
     // Get the active cache name
     $activeCache = Gdn_Cache::ActiveCache();
     $activeCache = ucfirst($activeCache);
     $sctiveStoreKey = "Cache.{$activeCache}.Store";
     // Get the localstore
     $localStore = GetValue($activeCache, Gdn_Cache::$Stores, null);
     if (is_null($localStore)) {
         Gdn_Cache::ActiveStore();
         $localStore = GetValue($activeCache, Gdn_Cache::$Stores, null);
         if (is_null($localStore)) {
             return false;
         }
     }
     $storeServerName = md5($server);
     if (!array_key_exists($storeServerName, $localStore)) {
         return false;
     }
     $storeServer =& $localStore[$storeServerName];
     $isActive =& $storeServer['Active'];
     if (!$isActive) {
         return false;
     }
     $fails =& $storeServer['Fails'];
     $fails++;
     $active = $isActive ? 'active' : 'inactive';
     // Check if we need to deactivate for 5 minutes
     if ($isActive && $storeServer['Fails'] > 3) {
         $isActive = false;
         $storeServer['Delay'] = time() + Gdn_Cache::CACHE_EJECT_DURATION;
     }
     // Save
     Gdn_Cache::$Stores[$activeCache] = $localStore;
     // Save to APC
     if ($apc) {
         apc_store($sctiveStoreKey, $localStore, Gdn_Cache::APC_CACHE_DURATION);
     }
     return true;
 }