Example #1
0
 * @link http://www.pradosoft.com/
 * @copyright Copyright © 2005-2014 PradoSoft
 * @license http://www.pradosoft.com/license/
 * @package System.Caching
 */
/**
 * TEACache class
 *
Example #2
0
 /**
  * Initializes this module.
  * This method is required by the IModule interface.
  * @param TXmlElement configuration for this module, can be null
  * @throws TConfigurationException if xcache extension is not installed or not started, check your php.ini
  */
 public function init($config)
 {
     if (!function_exists('xcache_isset')) {
         throw new TConfigurationException('xcache_extension_required');
     }
     $enabled = (int) ini_get('xcache.cacher') !== 0;
     $var_size = (int) ini_get('xcache.var_size');
     if (!($enabled && $var_size > 0)) {
         throw new TConfigurationException('xcache_extension_not_enabled');
     }
     parent::init($config);
 }
Example #3
0
 /**
  * Initializes this module.
  * This method is required by the IModule interface.
  * @param TXmlElement configuration for this module, can be null
  * @throws TConfigurationException if apc extension is not installed or not started, check your php.ini
  */
 public function init($config)
 {
     if (!extension_loaded('apc')) {
         throw new TConfigurationException('apccache_extension_required');
     }
     if (ini_get('apc.enabled') == false) {
         throw new TConfigurationException('apccache_extension_not_enabled');
     }
     if (substr(php_sapi_name(), 0, 3) === 'cli' and ini_get('apc.enable_cli') == false) {
         throw new TConfigurationException('apccache_extension_not_enabled_cli');
     }
     parent::init($config);
 }
Example #4
0
 /**
  * Initializes this module.
  * This method is required by the IModule interface. It makes sure that
  * UniquePrefix has been set, creates a Memcache instance and connects
  * to the memcache server.
  * @param TApplication Prado application, can be null
  * @param TXmlElement configuration for this module, can be null
  * @throws TConfigurationException if memcache extension is not installed or memcache sever connection fails
  */
 public function init($config)
 {
     if (!extension_loaded('memcache')) {
         throw new TConfigurationException('memcache_extension_required');
     }
     $this->_cache = new Memcache();
     $this->loadConfig($config);
     if (count($this->_servers)) {
         foreach ($this->_servers as $server) {
             Prado::trace('Adding server ' . $server['Host'] . ' from serverlist', 'System.Caching.TMemCache');
             if ($this->_cache->addServer($server['Host'], $server['Port'], $server['Persistent'], $server['Weight'], $server['Timeout'], $server['RetryInterval']) === false) {
                 throw new TConfigurationException('memcache_connection_failed', $server['Host'], $server['Port']);
             }
         }
     } else {
         Prado::trace('Adding server ' . $this->_host, 'System.Caching.TMemCache');
         if ($this->_cache->addServer($this->_host, $this->_port) === false) {
             throw new TConfigurationException('memcache_connection_failed', $this->_host, $this->_port);
         }
     }
     $this->_initialized = true;
     parent::init($config);
 }
 /**
  * Initializes this module.
  * This method is required by the IModule interface.
  * attach {@link doInitializeCache} to TApplication.OnLoadStateComplete event
  * attach {@link doFlushCacheExpired} to TApplication.OnSaveState event
  *
  * @param TXmlElement configuration for this module, can be null
  */
 public function init($config)
 {
     $this->getApplication()->attachEventHandler('OnLoadStateComplete', array($this, 'doInitializeCache'));
     $this->getApplication()->attachEventHandler('OnSaveState', array($this, 'doFlushCacheExpired'));
     parent::init($config);
 }
Example #6
0
 /**
  * Initializes this module.
  * This method is required by the IModule interface. It checks if the DbFile
  * property is set, and creates a SQLiteDatabase instance for it.
  * The database or the cache table does not exist, they will be created.
  * Expired values are also deleted.
  * @param TXmlElement configuration for this module, can be null
  * @throws TConfigurationException if sqlite extension is not installed,
  *         DbFile is set invalid, or any error happens during creating database or cache table.
  */
 public function init($config)
 {
     if (!function_exists('sqlite_open')) {
         throw new TConfigurationException('sqlitecache_extension_required');
     }
     if ($this->_file === null) {
         $this->_file = $this->getApplication()->getRuntimePath() . '/sqlite.cache';
     }
     $error = '';
     if (($this->_db = new SQLiteDatabase($this->_file, 0666, $error)) === false) {
         throw new TConfigurationException('sqlitecache_connection_failed', $error);
     }
     if (@$this->_db->query('DELETE FROM ' . self::CACHE_TABLE . ' WHERE expire<>0 AND expire<' . time()) === false) {
         if ($this->_db->query('CREATE TABLE ' . self::CACHE_TABLE . ' (key CHAR(128) PRIMARY KEY, value BLOB, expire INT)') === false) {
             throw new TConfigurationException('sqlitecache_table_creation_failed', sqlite_error_string(sqlite_last_error()));
         }
     }
     $this->_initialized = true;
     parent::init($config);
 }