public function __construct(array $options = array())
 {
     if (!isset($options['cacheClusterId'])) {
         throw new Kwf_Exception('required parameter: cacheClusterId');
     }
     $options['servers'] = Kwf_Util_Aws_ElastiCache_CacheClusterEndpoints::getCached($options['cacheClusterId']);
     parent::__construct($options);
 }
 /**
  * Constructor.
  * 
  * @see Zend_Cache_Backend_Memcached::__construct()
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     $this->_handle = self::_getPrivateProp($this, "_memcache");
 }
Beispiel #3
0
 /**
  * @return array
  */
 public function getCapabilities()
 {
     $capabilities = parent::getCapabilities();
     $capabilities["tags"] = true;
     return $capabilities;
 }
Beispiel #4
0
 /**
  * Returns a cache backend as configured.
  *
  * @return Zend_Cache_Backend
  * @throws Erfurt_Exception
  */
 private function _getCacheBackend()
 {
     if (null === $this->_cacheBackend) {
         $config = $this->getConfig();
         // check the type an whether type is supported
         $cacheType = $config->cache->backend->type;
         // caching is not enabled, use fake cache backend
         if (!$config->cache->frontend->enable) {
             $cacheType = "null";
         }
         switch (strtolower($cacheType)) {
             case 'memcached':
                 $options = $config->cache->backend->memcached->toArray();
                 $cache = new Zend_Cache_Backend_Memcached($options);
                 if (!$cache->save(time(), 'EF_lastConnect')) {
                     throw new Erfurt_Exception('Memcache server is not available.');
                 }
                 break;
             case 'apc':
                 $cache = new Zend_Cache_Backend_Apc();
                 break;
             case 'sqlite':
                 $options = $config->cache->backend->sqlite->toArray();
                 if (!in_array('cache_db_complete_path', array_keys($options))) {
                     throw new Erfurt_Exception('Cache database filename must be set for sqlite cache backend (cache_db_complete_path).');
                 }
                 $cache = new Zend_Cache_Backend_Sqlite($options);
                 break;
             case 'file':
                 $path = $config->cache->backend->file->cache_dir;
                 if (!$path) {
                     throw new Erfurt_App_Exception('No cache directory configured.');
                 }
                 if (!file_exists($path)) {
                     throw new Erfurt_App_Exception('Cache directory "' . $path . '" is not existing.');
                 }
                 if (!is_writable($path)) {
                     throw new Erfurt_App_Exception('Cache directory "' . $path . '" is not writable.');
                 }
                 $options = $config->cache->backend->file->toArray();
                 $cache = new Zend_Cache_Backend_File($options);
                 break;
             case 'database':
                 $cache = new Erfurt_Cache_Backend_Database();
                 break;
             case 'null':
                 $cache = new Erfurt_Cache_Backend_Null();
                 break;
             default:
                 throw new Erfurt_Exception('Cache type "' . $cacheType . '" is not supported.');
         }
         $this->_cacheBackend = $cache;
     }
     return $this->_cacheBackend;
 }
 public function getFillingPercentage()
 {
     $ret = parent::getFillingPercentage();
     $ret *= $this->_fillingPercentageFactor;
     return $ret;
 }
 /**
  * Load data from memcached, glue from several chunks if it was splitted upon save.
  *
  * @param string $id                     @see Zend_Cache_Backend_Memcached::load()
  * @param bool   $doNotTestCacheValidity @see Zend_Cache_Backend_Memcached::load()
  * @return bool|false|string
  */
 public function load($id, $doNotTestCacheValidity = false)
 {
     $data = parent::load($id, $doNotTestCacheValidity);
     if (is_string($data) && substr($data, 0, strlen(self::CODE_WORD)) == self::CODE_WORD) {
         // Seems we've got chunked data
         $arr = explode('|', $data);
         $chunks = isset($arr[1]) ? $arr[1] : false;
         $chunkData = array();
         if ($chunks && is_numeric($chunks)) {
             for ($i = 0; $i < $chunks; $i++) {
                 $chunk = parent::load($this->_getChunkId($id, $i), $doNotTestCacheValidity);
                 if (false === $chunk) {
                     // Some chunk in chain was not found, we can not glue-up the data:
                     // clean the mess and return nothing
                     $this->_cleanTheMess($id, $chunks);
                     return false;
                 }
                 $chunkData[] = $chunk;
             }
             return implode('', $chunkData);
         }
     }
     // Data has not been splitted to chunks on save
     return $data;
 }
 public function remove($id)
 {
     return parent::remove($this->_makeId($id));
 }
Beispiel #8
0
 private function removeSliced($id, $slicesAmount, $skipCheck = false)
 {
     $result = false;
     for ($i = 0; $i < $slicesAmount; $i++) {
         $sliceKey = $id . "_slice_" . $i;
         $result = parent::remove($sliceKey);
         // security check if the deletion fails
         if (!$result && !$skipCheck && $this->_memcache->get($sliceKey) !== false) {
             Logger::warn("Error deleting slice #" . $i . " for key " . $id . " (" . $sliceKey . ") - flushing memcache!");
             $result = $this->_memcache->flush();
         }
     }
     return $result;
 }