示例#1
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;
 }
示例#2
0
 /**
  * Determines the currently installed cache solution and returns a fresh instance of its object
  * 
  * @return Gdn_Cache
  */
 public static function Initialize($ForceEnable = FALSE, $ForceMethod = FALSE)
 {
     $AllowCaching = self::ActiveEnabled($ForceEnable);
     $ActiveCache = Gdn_Cache::ActiveCache();
     if ($ForceMethod !== FALSE) {
         $ActiveCache = $ForceMethod;
     }
     $ActiveCacheClass = 'Gdn_' . ucfirst($ActiveCache);
     if (!$AllowCaching || !$ActiveCache || !class_exists($ActiveCacheClass)) {
         $CacheObject = new Gdn_Dirtycache();
     } else {
         $CacheObject = new $ActiveCacheClass();
     }
     if (method_exists($CacheObject, 'Autorun')) {
         $CacheObject->Autorun();
     }
     // This should only fire when cache is loading automatically
     if (!func_num_args() && Gdn::PluginManager() instanceof Gdn_PluginManager) {
         Gdn::PluginManager()->FireEvent('AfterActiveCache');
     }
     return $CacheObject;
 }