All cache objects should extend this to ensure a consistent public api for caching.
Since: 2.0.10
Author: Tim Gunter (tim@vanillaforums.com)
コード例 #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('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);
    }
 }
コード例 #2
0
ファイル: class.filecache.php プロジェクト: seedbank/old-repo
 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);
 }
コード例 #3
0
 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;
 }
コード例 #4
0
ファイル: class.cache.php プロジェクト: 3marproof/vanilla
 /**
  * Clear local cache (process memory cache)
  *
  */
 protected static function LocalClear()
 {
     self::$localCache = array();
 }
コード例 #5
0
ファイル: bootstrap.php プロジェクト: vanilla/vanilla
}
// 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');
コード例 #6
0
ファイル: class.cache.php プロジェクト: rnovino/Garden
 /**
  * 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;
 }
コード例 #7
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;
 }
コード例 #8
0
ファイル: bootstrap.php プロジェクト: 3marproof/vanilla
}
// 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');
コード例 #9
0
 public function __construct()
 {
     parent::__construct();
     $this->CacheType = Gdn_Cache::CACHE_TYPE_NULL;
 }
コード例 #10
0
ファイル: class.dirtycache.php プロジェクト: kerphi/Garden
 public function __construct()
 {
     parent::__construct();
 }
コード例 #11
0
ファイル: class.cache.php プロジェクト: elpum/TgaForumBundle
 protected static function LocalSet($key, $value = null)
 {
     if (!is_array($key)) {
         $key = array($key => $value);
     }
     self::$localCache = array_merge(self::$localCache, $key);
 }
コード例 #12
0
ファイル: class.memcached.php プロジェクト: bishopb/vanilla
 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;
 }
コード例 #13
0
 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')));
 }