/** * Check for existence of the wincache extension This method cannot be invoked externally. The driver must * be instantiated using the `Cache::instance()` method. * * @param array configuration * @throws Kohana_Cache_Exception */ protected function __construct(array $config) { if (!extension_loaded('wincache')) { throw new Kohana_Cache_Exception('PHP wincache extension is not available.'); } parent::__construct($config); }
/** * Sets up the PDO SQLite table and * initialises the PDO connection * * @param array configuration * @throws Kohana_Cache_Exception */ protected function __construct(array $config) { parent::__construct($config); $database = Arr::get($this->_config, 'database', NULL); if ($database === NULL) { throw new Kohana_Cache_Exception('Database path not available in Kohana Cache configuration'); } // Load new Sqlite DB $this->_db = new PDO('sqlite:' . $database); // Test for existing DB $result = $this->_db->query("SELECT * FROM sqlite_master WHERE name = 'caches' AND type = 'table'")->fetchAll(); // If there is no table, create a new one if (0 == count($result)) { $database_schema = Arr::get($this->_config, 'schema', NULL); if ($database_schema === NULL) { throw new Kohana_Cache_Exception('Database schema not found in Kohana Cache configuration'); } try { // Create the caches table $this->_db->query(Arr::get($this->_config, 'schema', NULL)); } catch (PDOException $e) { throw new Kohana_Cache_Exception('Failed to create new SQLite caches table with the following error : :error', array(':error' => $e->getMessage())); } } }
/** * Responsiblity of the constructor is crucial. * 1.Get the cache file path. * 2.Create the cache file if it doesn't exists. * 3.Get the area data if the file exists. */ public function __construct() { parent::__construct(); $this->areaService = new AreaService(); $this->filepath = parent::$path . '/' . self::$filename; if (!file_exists($this->filepath)) { $this->provinces = $this->areaService->getProvincesWithoutDirect(); $this->provincesWithSub = $this->areaService->getProvincesWithoutDirect(); $this->areaService->fillSubareas($this->provincesWithSub); $this->cities = $this->areaService->getCitiesIncludeDirect(); $this->provinces_json = json_encode($this->provinces); $this->provincesWithSub_json = json_encode($this->provincesWithSub); $this->cities_json = json_encode($this->cities); $this->writeIntoFile($this->provinces_json, $this->provincesWithSub_json, $this->cities_json); } else { $areaCacheFile = fopen($this->filepath, 'r') or die('File: ' . $this->filepath . ' open failed!'); $this->provinces_json = fgets($areaCacheFile); $this->provincesWithSub_json = fgets($areaCacheFile); $this->cities_json = fgets($areaCacheFile); fclose($areaCacheFile); $this->provinces = json_decode($this->provinces_json); $this->provincesWithSub = json_decode($this->provincesWithSub_json); $this->cities = json_decode($this->cities_json); } }
/** * Check for existence of the APC extension This method cannot be invoked externally. The driver must * be instantiated using the `Cache::instance()` method. * @param array $config configuration * @throws Cache_Exception */ protected function __construct(array $config) { if (!extension_loaded('apc')) { throw new Cache_Exception('PHP APC extension is not available.'); } parent::__construct($config); }
public function __construct($prefix = '') { parent::__construct($prefix); if (is_null(self::$cache)) { // TODO allow configuring a RedisArray, see https://github.com/nicolasff/phpredis/blob/master/arrays.markdown#redis-arrays self::$cache = new \Redis(); $config = \OC::$server->getSystemConfig()->getValue('redis', array()); if (isset($config['host'])) { $host = $config['host']; } else { $host = '127.0.0.1'; } if (isset($config['port'])) { $port = $config['port']; } else { $port = 6379; } if (isset($config['timeout'])) { $timeout = $config['timeout']; } else { $timeout = 0.0; // unlimited } self::$cache->connect($host, $port, $timeout); } }
/** * Constructs the file cache driver. This method cannot be invoked externally. The file cache driver must * be instantiated using the `Cache::instance()` method. * * @param array config * @throws Cache_Exception */ protected function __construct(array $config) { // Setup parent parent::__construct($config); try { $directory = Arr::get($this->_config, 'cache_dir', Kohana::$cache_dir); $this->_cache_dir = new SplFileInfo($directory); } catch (ErrorException $e) { $this->_cache_dir = $this->_make_directory($directory, 0777, TRUE); } catch (UnexpectedValueException $e) { $this->_cache_dir = $this->_make_directory($directory, 0777, TRUE); } // If the defined directory is a file, get outta here if ($this->_cache_dir->isFile()) { throw new Cache_Exception('Unable to create cache directory as a file already exists : :resource', array(':resource' => $this->_cache_dir->getRealPath())); } // Check the read status of the directory if (!$this->_cache_dir->isReadable()) { throw new Cache_Exception('Unable to read from the cache directory :resource', array(':resource' => $this->_cache_dir->getRealPath())); } // Check the write status of the directory if (!$this->_cache_dir->isWritable()) { throw new Cache_Exception('Unable to write to the cache directory :resource', array(':resource' => $this->_cache_dir->getRealPath())); } }
/** * Check for existence of the APC extension * * @throws Kohana_Cache_Exception */ protected function __construct() { parent::__construct(); if (!extension_loaded('apc')) { throw new Kohana_Cache_Exception('PHP APC extension is not available.'); } }
/** * Check for existence of the eAccelerator extension * * @param array configuration * @throws Kohana_Cache_Exception */ protected function __construct(array $config) { if (!extension_loaded('eaccelerator')) { throw new Kohana_Cache_Exception('PHP eAccelerator extension is not available.'); } parent::__construct($config); }
/** * Check for existence of the APC extension * * [!!] This method cannot be invoked externally * * The driver must be instantiated using the `Cache::instance()` method. * * @param array $config configuration * * @throws Cache_Exception */ protected function __construct(array $config) { if (!function_exists('apc_store') or !ini_get('apc.enabled')) { throw new Cache_Exception('You must have PHP APC installed and enabled to use.'); } parent::__construct($config); }
/** * Constructs the file cache driver. This method cannot be invoked externally. The file cache driver must * be instantiated using the `Cache::instance()` method. * * @param array config * @throws Kohana_Cache_Exception */ protected function __construct(array $config) { // Setup parent parent::__construct($config); try { $directory = Arr::get($this->_config, 'cache_dir', APPPATH . Cache_File::CACHE_DIR); $this->_cache_dir = new RecursiveDirectoryIterator($directory); } catch (UnexpectedValueException $e) { if (!mkdir($directory, 0777, TRUE)) { throw new Kohana_Cache_Exception('Failed to create the defined cache directory : :directory', array(':directory' => $directory)); } chmod($directory, 0777); $this->_cache_dir = new RecursiveDirectoryIterator($directory); } // If the defined directory is a file, get outta here if ($this->_cache_dir->isFile()) { throw new Kohana_Cache_Exception('Unable to create cache directory as a file already exists : :resource', array(':resource' => $this->_cache_dir->getRealPath())); } // Check the read status of the directory if (!$this->_cache_dir->isReadable()) { throw new Kohana_Cache_Exception('Unable to read from the cache directory :resource', array(':resource' => $this->_cache_dir->getRealPath())); } // Check the write status of the directory if (!$this->_cache_dir->isWritable()) { throw new Kohana_Cache_Exception('Unable to write to the cache directory :resource', array(':resource' => $this->_cache_dir->getRealPath())); } }
public function __construct($options = array()) { parent::__construct($options); $this->file = $this->optionable[self::PARAM_DIRECTORY] . self::KEY_PREFIX; $this->fileTtl = $this->optionable[self::PARAM_DIRECTORY] . self::TTL_PREFIX; $this->directory = $this->optionable[self::PARAM_DIRECTORY]; // $this->throwDbException(); }
public function __construct($config) { parent::__construct($config); $servers = $this->_config['servers']; $server = array_shift($servers); $this->_redis = new Redis(); $this->_redis->connect($server['host'], $server['port']); }
/** * Constructs the memcached object * * @param array configuration * @throws Kohana_Cache_Exception */ public function __construct(array $config) { // Check that memcached is loaded if (!extension_loaded('memcached')) { throw new Kohana_Cache_Exception('Memcached extension is not loaded'); } parent::__construct($config); // Check whether this is a persistent connection if ($config['persistent'] == FALSE) { // Setup a non-persistent memcached connection $this->_memcached = new Memcached(); } else { // Setup a persistent memcached connection $this->_memcached = new Memcached($this->_config['persistent_id']); } // Load servers from configuration $servers = Arr::get($this->_config, 'servers', NULL); if (!$servers) { // Throw exception if no servers found in configuration throw new Kohana_Cache_Exception('No Memcache servers defined in configuration'); } // Add memcache servers foreach ($servers as $server) { if (!$this->_memcached->addServer($server['host'], $server['port'], $server['weight'])) { throw new Kohana_Cache_Exception('Could not connect to memcache host at \':host\' using port \':port\'', array(':host' => $server['host'], ':port' => $server['port'])); } } // Load memcached options from configuration $options = Arr::get($this->_config, 'options', NULL); // Make sure there are options to set if ($options != NULL) { // Set the options foreach ($options as $key => $value) { // Special cases for a few options switch ($key) { case 'serializer': $value = $this->_serializer_map[$value]; break; case 'hash': $value = $this->_hash_map[$value]; break; case 'distribution': $value = $this->_distribution_map[$value]; break; case 'prefix_key': // Throw exception is key prefix is greater than 128 characters if (strlen($value) > 128) { throw new Kohana_Cache_Exception('Memcached prefix key cannot exceed 128 characters'); } break; default: break; } $this->_memcached->setOption($this->_options_map[$key], $value); } } }
public function __construct($prefix = '') { parent::__construct($prefix); if (is_null(self::$cache)) { self::$cache = new \Memcached(); list($host, $port) = \OC_Config::getValue('memcached_server', array('localhost', 11211)); self::$cache->addServer($host, $port); } }
/** * Constructs the redis Kohana_Cache object * * @param array configuration * @throws Kohana_Cache_Exception */ public function __construct(array $config) { // Check for the Rediska module if (!class_exists('Rediska')) { throw new Kohana_Cache_Exception('Rediska module not loaded'); } parent::__construct($config); $instance = Arr::get($this->_config, 'instance', Rediska::DEFAULT_NAME); $this->_rediska = Rediska_Manager::get($instance); }
public function __construct() { parent::__construct(); $this->filepath = parent::$path . '/' . self::$filename; if (!file_exists($this->filepath)) { $this->huge_pics = $this->createDefaultCache($this->filepath); } else { $this->huge_pics = $this->readCacheFile(); } }
function __construct($bin) { global $conf; // Assign the path on the following order: bin specific -> default specific -> /tmp/filepath $this->fspath = $conf['cacherouter'][$bin]['path']; if (!isset($conf['cacherouter'][$bin]['path'])) { if (isset($conf['cacherouter']['default']['path'])) { $this->fspath = $conf['cacherouter']['default']['path']; } } parent::__construct($bin); }
/** * Sets up the MongoDB table and * initialises the MongoDB connection * * @param array $config configuration * @throws Cache_Exception */ protected function __construct(array $config) { parent::__construct($config); $database = Arr::get($this->_config, 'database', NULL); if ($database === NULL) { throw new Cache_Exception('Database path not available in Kohana Cache configuration'); } $this->_client = new MongoClient('mongodb://' . $this->_config['host'] . ':' . $this->_config['port']); $this->_database = $this->_client->{$database}; $this->_collection = $this->_database->{$this->_config['collection']}; $this->_collection->ensureIndex(array('tags' => 1)); $this->_collection->ensureIndex(array('lifetime' => 1)); }
function __construct($bin, $options, $default_options) { // Assign the path on the following order: bin specific -> default specific -> /tmp/filepath if (isset($options['path'])) { $this->fspath = $options['path']; } elseif (isset($default_options['path'])) { $this->fspath = $default_options['path']; } if (substr($this->fspath, -1) == '/') { $this->fspath = substr($this->fspath, 0, strlen($this->fspath) - 2); } parent::__construct($bin, $options, $default_options); }
protected function __construct(array $config) { parent::__construct($config); $this->_memcache = new Memcache(); $servers = $this->_config['servers']; $config = array('host' => 'localhost', 'port' => 11211, 'persistent' => FALSE, 'weight' => 1, 'timeout' => 1, 'retry_interval' => 15, 'status' => TRUE, 'failure_callback' => NULL); foreach ($servers as $server) { $server += $config; if (!$this->_memcache->addServer($server['host'], $server['port'], $server['persistent'], $server['weight'], $server['timeout'], $server['retry_interval'], $server['status'], $server['failure_callback'])) { throw new Kohana_Exception('Memcache could not connect to host \':host\' using port \':port\'', array(':host' => $server['host'], ':port' => $server['port'])); } } $this->_flags = Arr::get($this->_config, 'compression', FALSE) ? MEMCACHE_COMPRESSED : FALSE; }
/** Constructor that sets up the DiskCache. * * @param string $directory The directory to use. (Optional) * @access public */ public function __construct($directory = null) { parent::__construct(); if ($directory != null) { $this->directory = $directory; } else { $this->directory = sys_get_temp_dir() . '/lastfm.cache'; } if (!file_exists($this->directory)) { @mkdir($this->directory); } if (!is_dir($this->directory)) { $this->directory = dirname($this->directory); } }
/** * Check for existence of the PhpRedis extension * * [!!] This method cannot be invoked externally * * The driver must be instantiated using the `Cache::instance()` method. * * @param array $config configuration * * @throws Cache_Exception */ protected function __construct(array $config) { // Check that the PhpRedis extension is loaded. if (!extension_loaded('redis')) { throw new Cache_Exception('You must have PhpRedis installed and enabled to use.'); } // Define a default settings array. $default_settings = array('host' => 'localhost', 'port' => 6379); // Merge the default settings with the user-defined settings. $this->config(Arr::merge($default_settings, $config)); // Create a new Redis instance and start a connection using the settings provided. $this->_redis = new Redis(); $this->_redis->connect($this->config('host'), $this->config('port')); parent::__construct($config); }
/** * Constructs the redis Kohana_Cache object * * @param array configuration * @throws Kohana_Cache_Exception */ protected function __construct(array $config) { if (!extension_loaded('redis')) { throw new Cache_Exception('PHP redis extension is not available.'); } parent::__construct($config); $host = isset($config['host']) ? $config['host'] : $this->_default_config['host']; $port = isset($config['port']) ? $config['port'] : $this->_default_config['port']; $this->_redis = new Redis(); $this->_redis->connect($host, $port, 1); if (@$config['igbinary_serialize'] === true) { $this->_redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY); } $db_num = isset($config['db_num']) ? $config['db_num'] : $this->_default_config['db_num']; $this->_redis->select($db_num); }
/** * Sets up the PDO SQLite table and * initialises the PDO connection * * @throws Kohana_Cache_Exception */ protected function __construct() { parent::__construct(); $this->_db = new PDO('sqlite:' . Kohana::config('cache.sqlite.database')); // Test for existing DB $result = $this->_db->query("SELECT * FROM sqlite_master WHERE name = 'caches' AND type = 'table'")->fetchAll(); // If there is no table, create a new one if (0 == count($result)) { try { // Create the caches table $this->_db->query(Kohana::config('cache.sqlite.schema')); } catch (PDOException $e) { throw new Kohana_Cache_Exception('Failed to create new SQLite caches table with the following error : :error', array(':error' => $e->getMessage())); } } }
function __construct($bin) { global $conf; // Assign the servers on the following order: bin specific -> default specific -> localhost port 11211 $this->settings['servers'] = $conf['cacherouter'][$this->name]['server']; if (!isset($conf['cacherouter'][$this->name]['server'])) { if (isset($conf['cacherouter']['default']['server'])) { $this->settings['servers'] = $conf['cacherouter']['default']['server']; } else { $this->settings['servers'] = array('localhost:11211'); } } $this->settings['compress'] = isset($conf['cacherouter'][$this->name]['compress']) ? MEMCACHE_COMPRESSED : 0; $this->settings['shared'] = isset($conf['cacherouter'][$this->name]['shared']) ? $conf['cacherouter'][$this->name]['shared'] : TRUE; parent::__construct($bin); $this->connect(); }
public function __construct($prefix = '') { parent::__construct($prefix); if (is_null(self::$cache)) { self::$cache = new \Memcached(); $servers = \OC_Config::getValue('memcached_servers'); if (!$servers) { $server = \OC_Config::getValue('memcached_server'); if ($server) { $servers = array($server); } else { $servers = array(array('localhost', 11211)); } } self::$cache->addServers($servers); } }
protected function __construct(array $config) { if (!extension_loaded('memcached')) { // exception missing memcached extension throw new Kohana_Cache_Exception('memcached extension is not loaded'); } parent::__construct($config); $this->memcached_instance = new Memcached(); // load servers from configuration $servers = Arr::get($this->_config, 'servers', array()); if (empty($servers)) { // exception no server found throw new Kohana_Cache_Exception('no Memcached servers in config/cache.php'); } // load options from configuration $options = Arr::get($this->_config, 'options', array()); // set options foreach ($options as $option => $value) { if ($option === Memcached::OPT_SERIALIZER && $value === Memcached::SERIALIZER_IGBINARY && !Memcached::HAVE_IGBINARY) { // exception serializer Igbinary not supported throw new Kohana_Cache_Exception('serializer Igbinary not supported, please fix config/cache.php'); } if ($option === Memcached::OPT_SERIALIZER && $value === Memcached::SERIALIZER_JSON && !Memcached::HAVE_JSON) { // exception serializer JSON not supported throw new Kohana_Cache_Exception('serializer JSON not supported, please fix config/cache.php'); } $this->memcached_instance->setOption($option, $value); } // add servers foreach ($servers as $pos => $server) { $host = Arr::get($server, 'host'); $port = Arr::get($server, 'port', NULL); $weight = Arr::get($server, 'weight', NULL); $status = Arr::get($server, 'status', TRUE); if (!empty($host)) { // status can be used by an external healthcheck to mark the memcached instance offline if ($status === TRUE) { $this->memcached_instance->addServer($host, $port, $weight); } } else { // exception no server host throw new Kohana_Cache_Exception('no host defined for server[' . $pos . '] in config/cache.php'); } } }
/** * Constructor. * * @param mixed $options An options array, or an object that implements \ArrayAccess * * @since 1.0 * @throws \RuntimeException */ public function __construct($options = array()) { if (!extension_loaded('memcached') || !class_exists('Memcached')) { throw new \RuntimeException('Memcached not supported.'); } // Parent sets up the caching options and checks their type parent::__construct($options); // These options must be set to something, so if not set make them false if (!isset($this->options['memcache.pool'])) { $this->options['memcache.pool'] = false; } if (!isset($this->options['memcache.compress'])) { $this->options['memcache.compress'] = false; } if (!isset($this->options['memcache.servers'])) { $this->options['memcache.servers'] = false; } }
/** * Class constructor * * @param $options Configuration options */ public function __construct($options = array()) { if (empty($options['path'])) { if (!empty($options['cachedir'])) { $options['path'] = $options['cachedir']; } elseif (!empty($options[0])) { $options['path'] = $options[0]; } else { $options['path'] = (function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : '/tmp') . '/cache.' . $this->options['key']; } } $options['path'] = preg_replace('/\\{\\$(.*?)\\}/e', "isset(\$_SERVER['\$1']) ? \$_SERVER['\$1'] : \$_ENV['\$1']", $options['path']); if (!is_dir($options['path']) && (file_exists($options['path']) || !mkdir($options['path'], 0770, true))) { throw new Exception("Unable to create Cache of type 'file'. Directory '{$this->options['cachedir']}' does not exists and could not be created."); } parent::__construct($options); if ($this->options['gc_probability'] >= 1 || mt_rand(1, 1 / $this->options['gc_probability']) == 1) { $this->clean(); } }
function __construct($bin, $options, $default_options) { // Assign the servers on the following order: bin specific -> default specific -> localhost port 11211 if (isset($options['servers'])) { $this->settings['servers'] = $options['servers']; $this->settings['compress'] = isset($options['compress']) ? memcached_COMPRESSED : 0; $this->settings['shared'] = isset($options['shared']) ? $options['shared'] : TRUE; } else { if (isset($default_options['servers'])) { $this->settings['servers'] = $default_options['servers']; $this->settings['compress'] = isset($default_options['compress']) ? memcached_COMPRESSED : 0; $this->settings['shared'] = isset($default_options['shared']) ? $default_options['shared'] : TRUE; } else { $this->settings['servers'] = array('localhost:11211'); $this->settings['compress'] = 0; $this->settings['shared'] = TRUE; } } parent::__construct($bin, $options, $default_options); $this->connect(); }