Пример #1
0
 /**
  * 写入缓存
  * @access public
  * @param string $name 缓存变量名
  * @param mixed $value  存储数据
  * @param integer $expire  有效时间(秒)
  * @return boolean
  */
 public function set($name, $value, $expire = null)
 {
     if (is_null($expire)) {
         $expire = $this->options['expire'];
     }
     $name = $this->options['prefix'] . $name;
     if (xcache_set($name, $value, $expire)) {
         if ($this->options['length'] > 0) {
             // 记录缓存队列
             $queue = xcache_get('__info__');
             if (!$queue) {
                 $queue = [];
             }
             if (false === array_search($name, $queue)) {
                 array_push($queue, $name);
             }
             if (count($queue) > $this->options['length']) {
                 // 出列
                 $key = array_shift($queue);
                 // 删除缓存
                 xcache_unset($key);
             }
             xcache_set('__info__', $queue);
         }
         return true;
     }
     return false;
 }
Пример #2
0
 /**
  * Set cache element
  *
  * This method will throw only logical exceptions.
  * In case of failures, it will return a boolean false.
  *
  * @param   string  $name    Name for cache element
  * @param   mixed   $data    Data to cache
  * @param   int     $ttl     Time to live
  *
  * @return  bool
  * @throws \Comodojo\Exception\CacheException
  */
 public function set($name, $data, $ttl = null)
 {
     if (empty($name)) {
         throw new CacheException("Name of object cannot be empty");
     }
     if (is_null($data)) {
         throw new CacheException("Object content cannot be null");
     }
     if (!$this->isEnabled()) {
         return false;
     }
     $this->resetErrorState();
     try {
         $this->setTtl($ttl);
         $shadowName = $this->getNamespace() . "-" . md5($name);
         $shadowTtl = $this->ttl;
         $shadowData = serialize($data);
         $return = xcache_set($shadowName, $shadowData, $shadowTtl);
         if ($return === false) {
             $this->raiseError("Error writing cache (XCache), exiting gracefully");
             $this->setErrorState();
         }
     } catch (CacheException $ce) {
         throw $ce;
     }
     return $return;
 }
Пример #3
0
 public function set($key, $value, $ttl = 0)
 {
     if ($ttl > 0) {
         return xcache_set($key, $value, $ttl);
     }
     return xcache_set($key, $value);
 }
Пример #4
0
 /**
  */
 public function set($key, $data, $lifetime = 0)
 {
     $key = $this->_params['prefix'] . $key;
     if (xcache_set($key . '_expire', time(), $lifetime)) {
         xcache_set($key, $data, $lifetime);
     }
 }
Пример #5
0
 public function set($key, $value, $expire = 86400)
 {
     if (!$key) {
         return false;
     }
     return xcache_set($key, $value, $expire);
 }
Пример #6
0
 public static function set($key, $value, $expires = false)
 {
     global $config;
     $key = $config['cache']['prefix'] . $key;
     if (!$expires) {
         $expires = $config['cache']['timeout'];
     }
     switch ($config['cache']['enabled']) {
         case 'memcached':
             if (!self::$cache) {
                 self::init();
             }
             self::$cache->set($key, $value, $expires);
             break;
         case 'apc':
             apc_store($key, $value, $expires);
             break;
         case 'xcache':
             xcache_set($key, $value, $expires);
             break;
         case 'php':
             self::$cache[$key] = $value;
             break;
     }
 }
Пример #7
0
 /**
  * Set a value based on an id. Optionally add tags.
  * 
  * @param   string   id 
  * @param   string   data 
  * @param   integer  lifetime [Optional]
  * @return  boolean
  */
 public function set($id, $data, $lifetime = NULL)
 {
     if (NULL === $lifetime) {
         $lifetime = Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE);
     }
     return xcache_set($this->_sanitize_id($id), $data, $lifetime);
 }
Пример #8
0
 /**
  * Set cache
  *
  * @param string $key
  * @param mixed $value
  * @param int $ttl
  * @return boolean
  */
 public function set($key, $value, $ttl = null)
 {
     if (null === $ttl) {
         $ttl = $this->options['ttl'];
     }
     return xcache_set($key, $value, $ttl);
 }
Пример #9
0
 public function store($key, $value)
 {
     if (xcache_set($key, $value)) {
         xcache_inc('__known_xcache_size', strlen($value));
     }
     return false;
 }
Пример #10
0
 function set($key, $value, $ttl)
 {
     if (!ini_get('xcache.var_size')) {
         return;
     }
     @xcache_set($key, serialize($value), $ttl);
 }
Пример #11
0
 /**
  * Veriyi döndürür
  *
  * @param string $name
  * @return bool|mixed|string
  */
 public function get($name = '')
 {
     if (false === ($var = xcache_get($name))) {
         xcache_set($name, $var = parent::get($name));
     }
     return $var;
 }
Пример #12
0
 /**
  * Write value(s) to the cache
  *
  * @param string $key The key to uniquely identify the cached item
  * @param mixed $data The value to be cached
  * @param null|string $expiry A strtotime() compatible cache time. If no expiry time is set,
  *        then the default cache expiration time set with the cache configuration will be used.
  * @return closure Function returning boolean `true` on successful write, `false` otherwise.
  */
 public function write($key, $data, $expiry = null)
 {
     $expiry = $expiry ?: $this->_config['expiry'];
     return function ($self, $params) use($expiry) {
         return xcache_set($params['key'], $params['data'], strtotime($expiry) - time());
     };
 }
Пример #13
0
 public function set($id, $data, array $tags = NULL, $lifetime)
 {
     if (!empty($tags)) {
         Kohana::log('error', 'Cache: tags are unsupported by the Xcache driver');
     }
     return xcache_set($id, $data, $lifetime);
 }
Пример #14
0
 /**
  *	Store value in cache
  *	@return mixed|FALSE
  *	@param $key string
  *	@param $val mixed
  *	@param $ttl int
  **/
 function set($key, $val, $ttl = 0)
 {
     $fw = Base::instance();
     if (!$this->dsn) {
         return TRUE;
     }
     $ndx = $this->prefix . '.' . $key;
     $time = microtime(TRUE);
     if ($cached = $this->exists($key)) {
         list($time, $ttl) = $cached;
     }
     $data = $fw->serialize(array($val, $time, $ttl));
     $parts = explode('=', $this->dsn, 2);
     switch ($parts[0]) {
         case 'apc':
         case 'apcu':
             return apc_store($ndx, $data, $ttl);
         case 'redis':
             return $this->ref->set($ndx, $data, array('ex' => $ttl));
         case 'memcache':
             return memcache_set($this->ref, $ndx, $data, 0, $ttl);
         case 'wincache':
             return wincache_ucache_set($ndx, $data, $ttl);
         case 'xcache':
             return xcache_set($ndx, $data, $ttl);
         case 'folder':
             return $fw->write($parts[1] . $ndx, $data);
     }
     return FALSE;
 }
Пример #15
0
 /**
  * @param string $key
  * @param mixed $value
  * @param integer $ttl
  * @return mixed
  */
 public function set($key, $value, $ttl = null)
 {
     $serialized = serialize($value);
     if (null === $ttl) {
         return xcache_set($key, $serialized);
     }
     return xcache_set($key, $serialized, $ttl);
 }
Пример #16
0
 public function set($key, $value, $ttl = 0)
 {
     if ($ttl > 0) {
         return xcache_set($this->getNamespace() . $key, $value, $ttl);
     } else {
         return xcache_set($this->getNamespace() . $key, $value);
     }
 }
Пример #17
0
 public function set($key, $value, $type = "", $ttl = SESSION_EXPIRE)
 {
     $this->type = $type;
     if (xcache_set($this->_key($key), $value, $ttl)) {
         return TRUE;
     }
     return FALSE;
 }
Пример #18
0
 /**
  * Sets a value to the variable store
  * @param string $key The key of the variable
  * @param mixed $value The value of the variable
  * @param integer $timeToLive Set to a number of seconds to make the variable expire in that amount of time
  * @return null
  */
 public function set($key, $value = null, $timeToLive = null)
 {
     if ($value === null) {
         xcache_unset($key);
     } else {
         xcache_set($key, $value, $timeToLive);
     }
 }
Пример #19
0
 public function set($key, $value = "", $ttl = 600)
 {
     if (empty($value)) {
         return xcache_unset($key);
     } else {
         return xcache_set($key, $value);
     }
 }
Пример #20
0
 /**
  * (Plug-in replacement for memcache API) Delete data from the persistant cache.
  *
  * @param  mixed			Key name
  */
 function delete($key)
 {
     // Update list of e-objects
     global $ECACHE_OBJECTS;
     unset($ECACHE_OBJECTS[$key]);
     xcache_set(get_file_base() . 'ECACHE_OBJECTS', $ECACHE_OBJECTS, 0);
     xcache_unset($key);
 }
Пример #21
0
 /**
 +----------------------------------------------------------
 * 写入缓存
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param string $name 缓存变量名
 * @param mixed $value  存储数据
 +----------------------------------------------------------
 * @return boolen
 +----------------------------------------------------------
 */
 public function set($name, $value, $expire = '')
 {
     $this->W(1);
     if (empty($expire)) {
         $expire = $this->expire;
     }
     return xcache_set($name, $value, $expire);
 }
Пример #22
0
 public function set($key, $value, $type = '', $ttl = SESSION_EXPIRE)
 {
     $this->type = $type;
     if (xcache_set($this->_key($key), $value, $ttl)) {
         return true;
     }
     return false;
 }
Пример #23
0
 public function update($key, $value, $ttl = 0, $tableName, $connectionResource)
 {
     $key = $this->getRealKey($tableName, $key);
     if (xcache_isset($key)) {
         return xcache_set($key, $value, $ttl);
     }
     return false;
 }
Пример #24
0
 public function setMulti($items, $ttl = 0)
 {
     $status = FALSE;
     foreach ($items as $key => $value) {
         $status = xcache_set($key, $value, $ttl);
     }
     return $status;
 }
Пример #25
0
 /**
  * Writes parsed annotations to XCache
  *
  * @param string $key
  * @param \Phalcon\Annotations\Reflection $data
  * @throws Exception
  */
 public function write($key, $data)
 {
     if (is_string($key) === false || is_object($data) === false || $data instanceof Reflection === false) {
         throw new Exception('Invalid parameter type.');
     }
     $serialized = serialize($data);
     xcache_set(strtolower('_PHAN' . $key), $serialized);
 }
Пример #26
0
 /**
  * Store a value in the XCache object cache
  *
  * @param $key String: cache key
  * @param $value Mixed: object to store
  * @param $expire Int: expiration time
  * @return bool
  */
 public function set($key, $value, $expire = 0)
 {
     if (!$this->isInteger($value)) {
         $value = serialize($value);
     }
     xcache_set($key, $value, $expire);
     return true;
 }
Пример #27
0
 function set($name, $value, $ttl = 0)
 {
     $this->cur_query = "cache->set('{$name}')";
     $this->debug('start');
     $this->debug('stop');
     $this->cur_query = null;
     $this->num_queries++;
     return xcache_set($this->prefix . $name, $value, $ttl);
 }
Пример #28
0
 public function save($key, $value, $ttl)
 {
     $expires = 0;
     if ($ttl > 0) {
         $expires = time() + $ttl;
     }
     xcache_set($key . '_expires', $expires, $ttl);
     xcache_set($key, $value, $ttl);
 }
Пример #29
0
 /**
  * Put data into remote cache store
  *
  * @param	string		Cache unique key
  * @param	string		Cache value to add
  * @param	integer		[Optional] Time to live
  * @return	@e boolean
  */
 public function putInCache($key, $value, $ttl = 0)
 {
     $ttl = $ttl > 0 ? intval($ttl) : '';
     if ($ttl) {
         return xcache_set(md5($this->identifier . $key), $value, $ttl);
     } else {
         return xcache_set(md5($this->identifier . $key), $value);
     }
 }
Пример #30
0
 /**
  * Save cache content in XCache store.
  *
  * @param   string  $data    Data to store.
  * @return  void
  * @throws  \Hoa\Cache\Exception
  */
 public function store($data)
 {
     $this->clean();
     if (true === $this->_parameters->getParameter('serialize_content')) {
         $data = serialize($data);
     }
     xcache_set($this->getIdMd5(), $data, $this->_parameters->getParameter('lifetime'));
     return;
 }