Ejemplo n.º 1
0
 /**
  * Constructor
  * 
  * @param array $options associative array of options
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('memcache')) {
         Zend_Cache::throwException('The memcache extension must be loaded for using this backend !');
     }
     parent::__construct($options);
     if (isset($options['servers'])) {
         $value = $options['servers'];
         if (isset($value['host'])) {
             // in this case, $value seems to be a simple associative array (one server only)
             $value = array(0 => $value);
             // let's transform it into a classical array of associative arrays
         }
         $this->setOption('servers', $value);
     }
     $this->_memcache = new Memcache();
     foreach ($this->_options['servers'] as $server) {
         if (!array_key_exists('persistent', $server)) {
             $server['persistent'] = Zend_Cache_Backend_Memcached::DEFAULT_PERSISTENT;
         }
         if (!array_key_exists('port', $server)) {
             $server['port'] = Zend_Cache_Backend_Memcached::DEFAULT_PORT;
         }
         $this->_memcache->addServer($server['host'], $server['port'], $server['persistent']);
     }
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  *
  * @param  array $options associative array of options
  * @throws \Zend_Cache_Exception
  */
 public function __construct(array $options = [])
 {
     if (!extension_loaded('eaccelerator')) {
         \Zend_Cache::throwException('The eaccelerator extension must be loaded for using this backend !');
     }
     parent::__construct($options);
 }
Ejemplo n.º 3
0
 /**
  * Constructor
  *
  * @param array $options associative array of options
  * @throws Zend_Cache_Exception
  * @return void
  */
 public function __construct(array $options = [])
 {
     if (!extension_loaded('redis')) {
         Zend_Cache::throwException('The redis extension must be loaded for using this backend !');
     }
     parent::__construct($options);
     $this->_redis = new Redis();
     foreach ($this->_options['servers'] as $server) {
         if (!array_key_exists('port', $server)) {
             $server['port'] = self::DEFAULT_PORT;
         }
         if (!array_key_exists('host', $server)) {
             $server['host'] = self::DEFAULT_HOST;
         }
         if (!array_key_exists('persistent', $server)) {
             $server['persistent'] = self::DEFAULT_PERSISTENT;
         }
         if (!array_key_exists('dbindex', $server)) {
             $server['dbindex'] = self::DEFAULT_DBINDEX;
         }
         if ($server['persistent']) {
             $result = $this->_redis->pconnect($server['host'], $server['port']);
         } else {
             $result = $this->_redis->connect($server['host'], $server['port']);
         }
         if ($result) {
             $this->_redis->select($server['dbindex']);
         } else {
             $this->_redis = null;
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Чистит кеши
  *
  * @param int $cMode	Режим очистки кеша
  * @param array $aTags	Список тегов, актуально для режима Zend_Cache::CLEANING_MODE_MATCHING_TAG
  * @return bool
  */
 public function Clean($cMode = Zend_Cache::CLEANING_MODE_ALL, $aTags = array())
 {
     if (!$this->bUseCache) {
         return false;
     }
     return $this->oBackendCache->clean($cMode, $aTags);
 }
Ejemplo n.º 5
0
 /**
  * Constructor
  *
  * @param  array $options associative array of options
  * @throws Zend_Cache_Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     if (!function_exists('zend_shm_cache_store')) {
         Zend_Cache::throwException('Glitch_Cache_Backend_ZendShMem backend has to be used within Zend Server / Zend Platform environment.');
     }
     parent::__construct($options);
 }
Ejemplo n.º 6
0
 /**
  * Constructor
  *
  * @param  array $options associative array of options
  * @throws Zend_Cache_Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     if (!extension_loaded('xcache')) {
         Zend_Cache::throwException('The xcache extension must be loaded for using this backend !');
     }
     parent::__construct($options);
 }
Ejemplo n.º 7
0
 /**
  * Constructor
  *
  * @param array $options associative array of options
  * @throws Zend_Cache_Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     if (!extension_loaded('redis')) {
         Zend_Cache::throwException('The redis extension must be loaded for using this backend !');
     }
     $this->_redis = new Redis();
     parent::__construct($options);
 }
Ejemplo n.º 8
0
 /**
  * Interceptor child method to handle the case where a Model or
  * Database object is being set since it's not supported by the
  * standard backend interface
  *
  * @param string $name
  * @param mixed $value
  * @return void
  */
 public function setOption($name, $value)
 {
     if ($name == 'db_object') {
         $this->setDbObject($value);
     } else {
         parent::setOption($name, $value);
     }
 }
Ejemplo n.º 9
0
 /**
  * Retrieve any option via interception of the parent's statically held
  * options including the local option for a tag cache.
  *
  * @param  string $name
  * @return mixed
  */
 public function getOption($name)
 {
     if ($name == 'tag_cache') {
         return $this->getInnerCache();
     } else {
         return parent::getOption($name);
     }
 }
Ejemplo n.º 10
0
 /**
  * Interceptor child method to handle the case where an Inner
  * Cache object is being set since it's not supported by the
  * standard backend interface
  *
  * @param string $name
  * @param mixed $value
  * @return void
  */
 public function setOption($name, $value)
 {
     if ($name == 'tag_cache') {
         $this->setInnerCache($value);
     } else {
         parent::setOption($name, $value);
     }
 }
Ejemplo n.º 11
0
 /**
  * Retrieve any option via interception of the parent's statically held
  * options including the local option for a tag cache.
  *
  * @param  string $name
  * @return mixed
  */
 public function getOption($name)
 {
     $name = strtolower($name);
     if ($name == 'tag_cache') {
         return $this->getInnerCache();
     }
     return parent::getOption($name);
 }
Ejemplo n.º 12
0
 public function testCleanType()
 {
     $this->_model->allowUse('single_tag');
     $this->_model->allowUse('multiple_tags');
     $this->_cacheFrontend->expects($this->at(0))->method('clean')->with(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('TAG_ONE', 'TAG_TWO'));
     $this->_cacheFrontend->expects($this->at(1))->method('load')->with(strtoupper(Mage_Core_Model_Cache::INVALIDATED_TYPES))->will($this->returnValue(serialize(array('single_tag' => 1, 'multiple_tags' => 1))));
     $this->_cacheFrontend->expects($this->at(2))->method('save')->with(serialize(array('single_tag' => 1)), strtoupper(Mage_Core_Model_Cache::INVALIDATED_TYPES));
     $this->_model->cleanType('multiple_tags');
 }
Ejemplo n.º 13
0
 public function __construct(array $options = array())
 {
     if (isset($options['cache_id_prefix'])) {
         throw new Kwf_Exception("Unsupported optoin for Apcu backend: cache_id_prefix");
     }
     if (!extension_loaded('apcu')) {
         Zend_Cache::throwException('The apcu extension must be loaded for using this backend !');
     }
     parent::__construct($options);
 }
Ejemplo n.º 14
0
 /**
  * @param array $options
  */
 public function __construct(array $options = array())
 {
     if (!extension_loaded('mongo') || !version_compare(\Mongo::VERSION, '1.2.11', '>=')) {
         \Zend_Cache::throwException("At least 1.2.11 version of 'mongo' extension is required for using MongoDb cache backend");
     }
     if (empty($options['db'])) {
         \Zend_Cache::throwException("'db' option is not specified");
     }
     parent::__construct($options);
 }
Ejemplo n.º 15
0
 /**
  * Constructor
  *
  * @param array $options associative array of options
  * @throws Zend_Cache_Exception
  * @return void
  */
 public function __construct($options = array())
 {
     if ($options['backend'] instanceof Zend_Cache_Backend_Interface || $options['backend'] instanceof Tid_Zend_Cache_Backend_Abstract) {
         $this->_backend = $options['backend'];
     } else {
         Zend_Cache::throwException('The backend option is not correctly set!');
     }
     $this->_id = '__' . get_class($this) . '__';
     parent::__construct($options);
 }
Ejemplo n.º 16
0
 /**
  * Constructor
  *
  * @param  array $options Associative array of options
  * @throws Zend_cache_Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     if (is_null($this->_options['cache_db_complete_path'])) {
         Zend_Cache::throwException('cache_db_complete_path option has to set');
     }
     if (!extension_loaded('sqlite')) {
         Zend_Cache::throwException("Cannot use SQLite storage because the 'sqlite' extension is not loaded in the current PHP environment");
     }
     $this->_getConnection();
 }
Ejemplo n.º 17
0
 /**
  * Constructor
  *
  * @param array $options associative array of options
  * @throws Zend_Cache_Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     if (!empty($options['socket'])) {
         $options['connmode'] = self::CONN_SOCKET;
     }
     if (!extension_loaded('redis')) {
         Zend_Cache::throwException('The redis extension must be loaded for using this backend !');
     }
     $this->_redis = new Redis();
     parent::__construct($options);
 }
Ejemplo n.º 18
0
 /**
  * Constructor
  * 
  * @param array $options associative array of options
  */
 public function __construct($options = array())
 {
     if (!isset($options['cacheDBCompletePath'])) {
         Zend_Cache::throwException('cacheDBCompletePath option has to set');
     }
     $this->_db = @sqlite_open($options['cacheDBCompletePath']);
     if (!$this->_db) {
         Zend_Cache::throwException("Impossible to open " . $options['cacheDBCompletePath'] . " cache DB file");
     }
     parent::__construct($options);
 }
Ejemplo n.º 19
0
 /**
  * Constructor
  *
  * @param array $options associative array of options
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     if (empty($this->_options['adapter_callback'])) {
         if (!$this->_options['adapter'] instanceof Zend_Db_Adapter_Abstract) {
             Zend_Cache::throwException('Option "adapter" should be declared and extend Zend_Db_Adapter_Abstract!');
         }
     }
     if (empty($this->_options['data_table']) || empty($this->_options['tags_table'])) {
         Zend_Cache::throwException('Options "data_table" and "tags_table" should be declared!');
     }
 }
Ejemplo n.º 20
0
 /**
  * Constructor
  *
  * @param  array                $options associative array of options
  * @throws Zend_Cache_Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     $this->_backendOptions = $options;
     if (isset($this->_backendOptions['tagStorage'])) {
         $this->setOption('tagStorage', $this->_backendOptions['tagStorage']);
         unset($this->_backendOptions['tagStorage']);
     }
     if (isset($this->_backendOptions['backendClass'])) {
         $this->setOption('backendClass', $this->_backendOptions['backendClass']);
         unset($this->_backendOptions['backendClass']);
     }
     parent::__construct($options);
 }
Ejemplo n.º 21
0
 /**
  * Constructor
  *
  * @param array $options associative array of options
  */
 public function __construct($options = [])
 {
     parent::__construct($options);
     if (empty($this->_options['adapter_callback'])) {
         if (!$this->_options['adapter'] instanceof \Magento\Framework\DB\Adapter\AdapterInterface) {
             \Zend_Cache::throwException('Option "adapter" should be declared and extend \\Magento\\Framework\\DB\\Adapter\\AdapterInterface!');
         }
     }
     if (empty($this->_options['data_table']) && empty($this->_options['data_table_callback'])) {
         \Zend_Cache::throwException('Option "data_table" or "data_table_callback" should be declared!');
     }
     if (empty($this->_options['tags_table']) && empty($this->_options['tags_table_callback'])) {
         \Zend_Cache::throwException('Option "tags_table" or "tags_table_callback" should be declared!');
     }
 }
Ejemplo n.º 22
0
 /**
  * Constructor
  *
  * @param array $options associative array of options
  */
 public function __construct($options = [])
 {
     parent::__construct($options);
     if (empty($this->_options['adapter_callback'])) {
         if (!$this->_options['adapter'] instanceof \Zend_Db_Adapter_Abstract) {
             \Zend_Cache::throwException('Option "adapter" should be declared and extend \\Zend_Db_Adapter_Abstract!');
         }
     }
     if (empty($this->_options['data_table']) && empty($this->_options['data_table_callback'])) {
         \Zend_Cache::throwException('Option "data_table" or "data_table_callback" should be declared!');
     }
     if (empty($this->_options['tags_table']) && empty($this->_options['tags_table_callback'])) {
         \Zend_Cache::throwException('Option "tags_table" or "tags_table_callback" should be declared!');
     }
 }
Ejemplo n.º 23
0
 /**
  * Constructor
  *
  * @param array $options associative array of options
  * @throws Zend_Cache_Exception
  * @return void
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     if (is_array($options['backend'])) {
         $backendClass = $options['backend']['class'];
         $this->_backend = new $backendClass($options['backend']['options']);
     } else {
         if ($options['backend'] instanceof Zend_Cache_Backend_Interface) {
             $this->_backend = $options['backend'];
         } else {
             Zend_Cache::throwException('The backend option is not correctly set!');
         }
     }
     if (!is_array($options['table'])) {
         Zend_Cache::throwException('The table option is not correctly set!');
     }
 }
Ejemplo n.º 24
0
 /**
  * Constructor
  * Validate that the Zend Platform is loaded and licensed
  *
  * @param array $options associative array of options
  */
 public function __construct($options = array())
 {
     if (!function_exists('accelerator_license_info')) {
         Zend_Cache::throwException('The Zend Platform extension must be loaded for using this backend !');
     }
     if (!function_exists('accelerator_get_configuration')) {
         $licenseInfo = accelerator_license_info();
         Zend_Cache::throwException('The Zend Platform extension is not loaded correctly: ' . $licenseInfo['failure_reason']);
     }
     $accConf = accelerator_get_configuration();
     if (@(!$accConf['output_cache_licensed'])) {
         Zend_Cache::throwException('The Zend Platform extension does not have the proper license to use content caching features');
     }
     if (@(!$accConf['output_cache_enabled'])) {
         Zend_Cache::throwException('The Zend Platform content caching feature must be enabled for using this backend, set the \'zend_accelerator.output_cache_enabled\' directive to On !');
     }
     if (!is_writable($accConf['output_cache_dir'])) {
         Zend_Cache::throwException('The cache copies directory \'' . ini_get('zend_accelerator.output_cache_dir') . '\' must be writable !');
     }
     parent::__construct($options);
 }
Ejemplo n.º 25
0
 private function _getFastFillingPercentage($mode)
 {
     if ($mode == 'saving') {
         // mode saving
         if (is_null($this->_fastBackendFillingPercentage)) {
             $this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
         } else {
             $rand = rand(1, $this->_options['stats_update_factor']);
             if ($rand == 1) {
                 // we force a refresh
                 $this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
             }
         }
     } else {
         // mode loading
         // we compute the percentage only if it's not available in cache
         if (is_null($this->_fastBackendFillingPercentage)) {
             $this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
         }
     }
     return $this->_fastBackendFillingPercentage;
 }
Ejemplo n.º 26
0
 /**
  * Constructor
  *
  * @param  array $options associative array of options
  * @throws Zend_Cache_Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     if ($this->_options['cache_dir'] !== null) {
         // particular case for this option
         $this->setCacheDir($this->_options['cache_dir']);
     } else {
         $this->setCacheDir(self::getTmpDir() . DIRECTORY_SEPARATOR, false);
     }
     if (isset($this->_options['file_name_prefix'])) {
         // particular case for this option
         if (!preg_match('~^[\\w]+$~', $this->_options['file_name_prefix'])) {
             Zend_Cache::throwException('Invalid file_name_prefix : must use only [a-zA-A0-9_]');
         }
     }
     if ($this->_options['metadatas_array_max_size'] < 10) {
         Zend_Cache::throwException('Invalid metadatas_array_max_size, must be > 10');
     }
     if (isset($options['hashed_directory_umask']) && is_string($options['hashed_directory_umask'])) {
         // See #ZF-4422
         $this->_options['hashed_directory_umask'] = octdec($this->_options['hashed_directory_umask']);
     }
     if (isset($options['cache_file_umask']) && is_string($options['cache_file_umask'])) {
         // See #ZF-4422
         $this->_options['cache_file_umask'] = octdec($this->_options['cache_file_umask']);
     }
 }
Ejemplo n.º 27
0
 /**
  * Set the frontend directives
  *
  * @param  array $directives Assoc of directives
  * @throws Zend_Cache_Exception
  * @return void
  */
 public function setDirectives($directives)
 {
     parent::setDirectives($directives);
     $lifetime = $this->getLifetime(false);
     if ($lifetime > 2592000) {
         // #ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)
         $this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
     }
     if ($lifetime === null) {
         // #ZF-4614 : we tranform null to zero to get the maximal lifetime
         parent::setDirectives(array('lifetime' => 0));
     }
 }
Ejemplo n.º 28
0
 /**
  * Retrieve any option via interception of the parent's statically held
  * options including the local option for a tag cache.
  *
  * @param  string $name
  * @return mixed
  */
 public function getOption($name)
 {
     if ($name == 'tag_cache') {
         return $this->getInnerCache();
     } else {
         if (in_array($name, $this->_options)) {
             return $this->_options[$name];
         }
         if ($name == 'lifetime') {
             return parent::getLifetime();
         }
         return null;
     }
 }
Ejemplo n.º 29
0
 /**
  * Constructor
  *
  * @param  array $options Associative array of options
  * @throws Zend_Cache_Exception
  * @return void
  */
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     if ($this->_options['slow_backend'] === null) {
         Zend_Cache::throwException('slow_backend option has to set');
     } elseif ($this->_options['slow_backend'] instanceof Zend_Cache_Backend_ExtendedInterface) {
         $this->_slowBackend = $this->_options['slow_backend'];
     } else {
         $this->_slowBackend = Zend_Cache::_makeBackend($this->_options['slow_backend'], $this->_options['slow_backend_options'], $this->_options['slow_backend_custom_naming'], $this->_options['slow_backend_autoload']);
         if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_slowBackend))) {
             Zend_Cache::throwException('slow_backend must implement the Zend_Cache_Backend_ExtendedInterface interface');
         }
     }
     if ($this->_options['fast_backend'] === null) {
         Zend_Cache::throwException('fast_backend option has to set');
     } elseif ($this->_options['fast_backend'] instanceof Zend_Cache_Backend_ExtendedInterface) {
         $this->_fastBackend = $this->_options['fast_backend'];
     } else {
         $this->_fastBackend = Zend_Cache::_makeBackend($this->_options['fast_backend'], $this->_options['fast_backend_options'], $this->_options['fast_backend_custom_naming'], $this->_options['fast_backend_autoload']);
         if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_fastBackend))) {
             Zend_Cache::throwException('fast_backend must implement the Zend_Cache_Backend_ExtendedInterface interface');
         }
     }
     $this->_slowBackend->setDirectives($this->_directives);
     $this->_fastBackend->setDirectives($this->_directives);
 }
Ejemplo n.º 30
0
 /**
  * Set the frontend directives
  *
  * @param  array $directives Assoc of directives
  * @throws Zend_Cache_Exception
  * @return void
  */
 public function setDirectives($directives)
 {
     parent::setDirectives($directives);
     $lifetime = $this->getLifetime(false);
     if ($lifetime > 2592000) {
         # ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)
         $this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
     }
 }