Gdn_Cache::activeCache PHP Method

activeCache() public static method

This method retrieves the name of the active cache according to the config file. It fires an event thereafter, allowing that value to be overridden by loaded plugins.
public static activeCache ( ) : string
return string shortname of current auto active cache
    public static function activeCache()
    {
        /*
         * There is a catch 22 with caching the config file. We need
         * an external way to define the cache layer before needing it
         * in the config.
         */
        if (defined('CACHE_METHOD_OVERRIDE')) {
            $ActiveCache = CACHE_METHOD_OVERRIDE;
        } else {
            $ActiveCache = c('Cache.Method', false);
        }
        // This should only fire when cache is loading automatically
        if (!func_num_args() && Gdn::pluginManager() instanceof Gdn_PluginManager) {
            Gdn::pluginManager()->EventArguments['ActiveCache'] =& $ActiveCache;
            Gdn::pluginManager()->fireEvent('BeforeActiveCache');
        }
        return $ActiveCache;
    }

Usage Example

 /**
  * 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);
     $activeStoreKey = "Cache.{$activeCache}.Store";
     // Get the local store.
     $localStore = val($activeCache, Gdn_Cache::$stores, null);
     if (is_null($localStore)) {
         Gdn_Cache::activeStore();
         $localStore = val($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($activeStoreKey, $localStore, Gdn_Cache::APC_CACHE_DURATION);
     }
     return true;
 }