/** * 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); } }
public function __construct() { parent::__construct(); $this->CacheType = Gdn_Cache::CACHE_TYPE_FILE; $this->RegisterFeature(Gdn_Cache::FEATURE_COMPRESS, array('gzcompress', 'gzuncompress')); $this->RegisterFeature(Gdn_Cache::FEATURE_EXPIRY); $this->RegisterFeature(Gdn_Cache::FEATURE_TIMEOUT); }
public function Decrement($Key, $Amount = 1, $Options = array()) { $FinalOptions = array_merge($this->StoreDefaults, $Options); $Initial = GetValue(Gdn_Cache::FEATURE_INITIAL, $FinalOptions, NULL); $Expiry = GetValue(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); break; case TRUE: $Decremented = $this->Memcache->decrement($RealKey, $Amount, $Initial, $Expiry); break; } if ($Decremented !== FALSE) { Gdn_Cache::LocalSet($RealKey, $Decremented); return $Decremented; } return Gdn_Cache::CACHEOP_FAILURE; }
/** * Clear local cache (process memory cache) * */ protected static function LocalClear() { self::$localCache = array(); }
} // Re-apply loaded user settings. Gdn::config()->overlayDynamic(); /** * Bootstrap Late * * All configurations are loaded, as well as the Application, Plugin and Theme * managers. */ if (file_exists(PATH_CONF . '/bootstrap.late.php')) { require_once PATH_CONF . '/bootstrap.late.php'; } if (c('Debug')) { debug(true); } Gdn_Cache::trace(debug()); /** * Factory Services * * These are the helper classes that facilitate Garden's operation. They can be * overwritten using FactoryOverwrite, but their defaults are installed here. */ // Default database. Gdn::factoryInstall(Gdn::AliasDatabase, 'Gdn_Database', null, Gdn::FactorySingleton, array('Database')); // Database drivers. Gdn::factoryInstall('MySQLDriver', 'Gdn_MySQLDriver', null, Gdn::FactoryInstance); Gdn::factoryInstall('MySQLStructure', 'Gdn_MySQLStructure', null, Gdn::FactoryInstance); // Form class Gdn::factoryInstall('Form', 'Gdn_Form', null, Gdn::FactoryInstance); // Identity, Authenticator & Session. Gdn::factoryInstall('Identity', 'Gdn_CookieIdentity');
/** * 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; }
/** * {@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; }
} // Re-apply loaded user settings Gdn::Config()->OverlayDynamic(); /** * Bootstrap Late * * All configurations are loaded, as well as the Application, Plugin and Theme * managers. */ if (file_exists(PATH_CONF . '/bootstrap.late.php')) { require_once PATH_CONF . '/bootstrap.late.php'; } if (C('Debug')) { Debug(TRUE); } Gdn_Cache::Trace(Debug()); /** * Factory Services * * These are the helper classes that facilitate Garden's operation. They can be * overwritten using FactoryOverwrite, but their defaults are installed here. */ // Default database. Gdn::FactoryInstall(Gdn::AliasDatabase, 'Gdn_Database', NULL, Gdn::FactorySingleton, array('Database')); // Database drivers. Gdn::FactoryInstall('MySQLDriver', 'Gdn_MySQLDriver', NULL, Gdn::FactoryInstance); Gdn::FactoryInstall('MySQLStructure', 'Gdn_MySQLStructure', NULL, Gdn::FactoryInstance); // Form class Gdn::FactoryInstall('Form', 'Gdn_Form', NULL, Gdn::FactoryInstance); // Identity, Authenticator & Session. Gdn::FactoryInstall('Identity', 'Gdn_CookieIdentity');
public function __construct() { parent::__construct(); $this->CacheType = Gdn_Cache::CACHE_TYPE_NULL; }
public function __construct() { parent::__construct(); }
protected static function LocalSet($key, $value = null) { if (!is_array($key)) { $key = array($key => $value); } self::$localCache = array_merge(self::$localCache, $key); }
public function Decrement($key, $amount = 1, $options = array()) { if (!$this->Online()) { return Gdn_Cache::CACHEOP_FAILURE; } $finalOptions = array_merge($this->StoreDefaults, $options); $initial = GetValue(Gdn_Cache::FEATURE_INITIAL, $finalOptions, NULL); $expiry = GetValue(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); 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; }
public function __construct() { parent::__construct(); $this->RegisterFeature(Gdn_Cache::FEATURE_COMPRESS, array('gzcompress', 'gzuncompress')); $this->AddContainer(array(Gdn_Cache::CONTAINER_LOCATION => C('Cache.Filecache.Store'))); }