示例#1
0
 /**
  * Устанавливает значение кэша для плагина
  * 
  * @param string $plugin Название плагина
  * @param \Phalcon\Http\Request $request Запрос
  * @param array $result Значение
  */
 public function set($plugin, Request $request, $result)
 {
     if (!$this->useCache()) {
         return;
     }
     $key = $this->getCacheKey($plugin, $request);
     return $this->cache->save($key, $result);
 }
示例#2
0
文件: Redis.php 项目: rj28/test
 /**
  * Phalcon\Cache\Backend\Redis constructor
  *
  * @param \Phalcon\Cache\FrontendInterface $frontend
  * @param array $options
  * @throws \Phalcon\Cache\Exception
  */
 public function __construct($frontend, $options = null)
 {
     if (!isset($options['redis'])) {
         throw new Exception("Parameter 'redis' is required");
     }
     parent::__construct($frontend, $options);
 }
示例#3
0
 /**
  * Phalcon\Cache\Backend\Memcache\Memcached constructor
  *
  * @param \Phalcon\Cache\FrontendInterface $frontend
  * @param array $options
  */
 public function __construct($frontend, $options = null)
 {
     $this->_memcache = new NativeMemcache();
     if (!isset($options['servers'])) {
         $options['servers'] = array(array('host' => self::DEFAULT_HOST));
     }
     foreach ($options['servers'] as $server) {
         if (!array_key_exists('port', $server)) {
             $server['port'] = self::DEFAULT_PORT;
         }
         if (!array_key_exists('persistent', $server)) {
             $server['persistent'] = self::DEFAULT_PERSISTENT;
         }
         if (!array_key_exists('weight', $server)) {
             $server['weight'] = self::DEFAULT_WEIGHT;
         }
         if (!array_key_exists('timeout', $server)) {
             $server['timeout'] = self::DEFAULT_TIMEOUT;
         }
         if (!array_key_exists('retry_interval', $server)) {
             $server['retry_interval'] = self::DEFAULT_RETRY_INTERVAL;
         }
         $this->_memcache->addServer($server['host'], $server['port'], $server['persistent'], $server['weight'], $server['timeout'], $server['retry_interval']);
     }
     if (!isset($options['tracking'])) {
         $options['tracking'] = self::DEFAULT_TRACKING;
     }
     if (!isset($options['tracking_key'])) {
         $options['tracking_key'] = self::DEFAULT_TRACKING_KEY;
     }
     parent::__construct($frontend, $options);
 }
示例#4
0
 /**
  * \Phalcon\Cache\Backend\File constructor
  *
  * @param \Phalcon\Cache\FrontendInterface $frontend
  * @param array $options
  * @throws Exception
  */
 public function __construct($frontend, $options = null)
 {
     if (is_array($options) === false || isset($options['cacheDir']) === false) {
         throw new Exception('Cache directory must be specified with the option cacheDir');
     }
     parent::__construct($frontend, $options);
 }
示例#5
0
 /**
  * Phalcon\Cache\Backend\Database constructor
  *
  * @param Phalcon\Cache\FrontendInterface $frontend
  * @param array $options
  */
 public function __construct($frontend, $options = array())
 {
     if (!isset($options['db'])) {
         throw new Exception("Parameter 'db' is required");
     }
     if (!isset($options['table'])) {
         throw new Exception("Parameter 'table' is required");
     }
     parent::__construct($frontend, $options);
 }
示例#6
0
 /**
  * \Phalcon\Cache\Backend\Xcache constructor
  *
  * @param \Phalcon\Cache\FrontendInterface $frontend
  * @param array|null $options
  */
 public function __construct($frontend, $options = null)
 {
     if (is_array($options) === false) {
         $options = array();
     }
     if (isset($options['statsKey']) === false) {
         $options['statsKey'] = '_PHCX';
     }
     parent::__construct($frontend, $options);
 }
 /**
  * Removes a session variable from an application context
  *
  * @param string $index
  */
 public function remove($index)
 {
     if (!$this->is_started) {
         $this->start();
     }
     $name = $this->getName($index);
     if (isset($this->_data[$name])) {
         unset($this->_data[$name]);
     }
     $this->cache->delete($name);
 }
示例#8
0
 /**
  * {@inheritdoc}
  *
  * @param  FrontendInterface $frontend
  * @param  array             $options
  * @throws Exception
  */
 public function __construct(FrontendInterface $frontend, array $options)
 {
     if (!isset($options['db']) || !$options['db'] instanceof DbAdapterInterface) {
         throw new Exception('Parameter "db" is required and it must be an instance of Phalcon\\Acl\\AdapterInterface');
     }
     if (!isset($options['table']) || empty($options['table']) || !is_string($options['table'])) {
         throw new Exception("Parameter 'table' is required and it must be a non empty string");
     }
     $this->db = $options['db'];
     $this->table = $this->db->escapeIdentifier($options['table']);
     unset($options['db'], $options['table']);
     parent::__construct($frontend, $options);
 }
示例#9
0
 /**
  * \Phalcon\Cache\Backend\Mongo constructor
  *
  * @param \Phalcon\Cache\FrontendInterface $frontend
  * @param array|null $options
  * @throws Exception
  */
 public function __construct($frontend, $options = null)
 {
     if (is_array($options) === false) {
         $options = array();
     }
     if (isset($options['mongo']) === false && isset($options['server']) === false) {
         throw new Exception('The parameter \'server\' is required');
     }
     if (isset($options['db']) === false) {
         throw new Exception('The parameter \'db\' is required');
     }
     if (isset($options['collection']) === false) {
         throw new Exception("The parameter 'collection' is required");
     }
     parent::__construct($frontend, $options);
 }
示例#10
0
文件: Manager.php 项目: biggtfish/cms
 /**
  * Prints the HTML for CSS resources.
  *
  * @param string $collectionName the name of the collection
  *
  * @return string
  **/
 public function outputCss($collectionName = self::DEFAULT_COLLECTION_CSS)
 {
     $remote = $this->_config->application->assets->get('remote');
     $collection = $this->collection($collectionName);
     if (!$remote && $collection->getJoin()) {
         $local = $this->_config->application->assets->get('local');
         $lifetime = $this->_config->application->assets->get('lifetime', 0);
         $filepath = $local . self::GENERATED_STORAGE_PATH . ($filename = $filename = $this->getCollectionFileName($collection, self::FILENAME_PATTERN_CSS));
         $collection->setTargetPath($filepath)->setTargetUri($filepath);
         if ($this->_cache->exists($filename)) {
             return Tag::stylesheetLink($collection->getTargetUri());
         }
         $res = parent::outputCss($collectionName);
         $this->_cache->save($filename, true, $lifetime);
         return $res;
     }
     return parent::outputCss($collectionName);
 }
示例#11
0
 /**
  * \Engine\Cache\Backend\Redis constructor
  *
  * @param \Phalcon\Cache\FrontendInterface $frontend
  * @param array $options
  * @throws \Phalcon\Cache\Exception
  */
 public function __construct($frontend, $options = null)
 {
     if (!isset($options['redis'])) {
         throw new \Exception("Parameter 'redis' is required");
     }
     if (is_array($options['redis'])) {
         if (!isset($options['redis']['host'])) {
             throw new \Exception("Parameter 'redis host' is required");
         }
         if (!isset($options['redis']['port'])) {
             throw new \Exception("Parameter 'redis port' is required");
         }
         $redis = new \Redis();
         $redis->connect($options['redis']['host'], $options['redis']['port']);
         $options['redis'] = $redis;
     }
     parent::__construct($frontend, $options);
 }
示例#12
0
 /**
  * \Phalcon\Cache\Backend\Memcache constructor
  *
  * @param \Phalcon\Cache\FrontendInterface $frontend
  * @param array|null $options
  */
 public function __construct($frontend, $options = null)
 {
     if (is_null($options) === true) {
         $options = array();
     }
     if (isset($options['host']) === false) {
         $options['host'] = '127.0.0.1';
     }
     if (isset($options['port']) === false) {
         $options['port'] = '11211';
     }
     if (isset($options['persistent']) === false) {
         $options['persistent'] = false;
     }
     if (isset($options['statsKey']) === false) {
         $options['statsKey'] = '_PHCM';
     }
     parent::__construct($frontend, $options);
 }
示例#13
0
 /**
  * @param FrontendInterface $frontend
  * @param array $options
  */
 public function __construct($frontend, $options = array())
 {
     $this->_backend = new MemcachedDriver(self::DRIVER_PERSISTENCE_ID);
     if (!isset($options['servers'])) {
         $options['servers'] = array(array('host' => self::DEFAULT_HOST));
     }
     foreach ($options['servers'] as $server) {
         if (!array_key_exists('port', $server)) {
             $server['port'] = self::DEFAULT_PORT;
         }
         if (!array_key_exists('weight', $server)) {
             $server['weight'] = self::DEFAULT_WEIGHT;
         }
         $this->_backend->addServer($server['host'], $server['port'], $server['weight']);
     }
     if (isset($options['client']) && is_array($options['client'])) {
         $this->_backend->setOptions($options['client']);
     }
     unset($options['servers'], $options['client']);
     parent::__construct($frontend, $options);
 }
示例#14
0
 /**
  * Phalcon\Cache\Backend\Aerospike constructor
  *
  * @param  FrontendInterface $frontend Frontend Interface
  * @param  array             $options  Constructor options
  * @throws Exception
  */
 public function __construct(FrontendInterface $frontend, array $options)
 {
     if (!isset($options['hosts']) || !is_array($options['hosts'])) {
         throw new Exception('No hosts given in options');
     }
     if (isset($options['namespace'])) {
         $this->namespace = $options['namespace'];
     }
     if (isset($options['prefix'])) {
         $this->_prefix = $options['prefix'];
     }
     $persistent = false;
     if (isset($options['persistent'])) {
         $persistent = (bool) $options['persistent'];
     }
     $opts = [];
     if (isset($options['options']) && is_array($options['options'])) {
         $opts = $options['options'];
     }
     $this->db = new AerospikeDb(['hosts' => $options['hosts']], $persistent, $opts);
     if (!$this->db->isConnected()) {
         throw new Exception(sprintf("Aerospike failed to connect [%s]: %s", $this->db->errorno(), $this->db->error()));
     }
     parent::__construct($frontend, $options);
 }
示例#15
0
 public function reset($keyName)
 {
     $this->cache->save($this->prefix . $keyName, 0);
 }
示例#16
0
 public static function set($key, $value, $ttl = null)
 {
     static::$cache === null and static::$cache = static::$di->getShared('cache');
     static::$cache->save($key, $value, $ttl);
 }