Ejemplo n.º 1
0
 /**
  * Set a value based on an id. Optionally add tags.
  * 
  * @param   string   id 
  * @param   mixed    data 
  * @param   integer  lifetime [Optional]
  * @return  boolean
  */
 public function set($id, $data, $lifetime = NULL)
 {
     if (NULL === $lifetime) {
         $lifetime = time() + $this->_default_expire;
     }
     return eaccelerator_put($this->sanitize_id($id), $data, $lifetime);
 }
 public function set($id, $data, array $tags = NULL, $lifetime)
 {
     if (!empty($tags)) {
         Kohana::log('error', 'tags are unsupported by the eAccelerator driver');
     }
     return eaccelerator_put($id, $data, $lifetime);
 }
 /**
  * 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 eaccelerator_put($key, $value, $ttl);
 }
Ejemplo n.º 4
0
 /**
  * Write an item to the cache.
  *
  * @param string The name of the cache
  * @param mixed The data to write to the cache item
  * @return boolean True on success, false on failure
  */
 function put($name, $contents)
 {
     eaccelerator_lock($this->unique_id . "_" . $name);
     $status = eaccelerator_put($this->unique_id . "_" . $name, serialize($contents));
     eaccelerator_unlock($this->unique_id . "_" . $name);
     return $status;
 }
Ejemplo n.º 5
0
 /**
  * 写入缓存
  * @access public
  * @param string $name 缓存变量名
  * @param mixed $value  存储数据
  * @param integer $expire  有效时间(秒)
  * @return boolen
  */
 public function set($name, $value, $expire = null)
 {
     \think\Cache::$writeTimes++;
     if (is_null($expire)) {
         $expire = $this->options['expire'];
     }
     $name = $this->options['prefix'] . $name;
     eaccelerator_lock($name);
     if (eaccelerator_put($name, $value, $expire)) {
         if ($this->options['length'] > 0) {
             // 记录缓存队列
             $queue = eaccelerator_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);
                 // 删除缓存
                 eaccelerator_rm($key);
             }
             eaccelerator_put('__info__', $queue);
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 6
0
 /**
  * Set a value based on an id. Optionally add tags.
  * 
  * @param   string   id 
  * @param   mixed    data 
  * @param   integer  lifetime [Optional]
  * @return  boolean
  */
 public function set($id, $data, $lifetime = NULL)
 {
     if ($lifetime === NULL) {
         $lifetime = time() + Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE);
     }
     return eaccelerator_put($this->_sanitize_id($id), $data, $lifetime);
 }
Ejemplo n.º 7
0
function getClassPath()
{
    static $classpath = array();
    if (!empty($classpath)) {
        return $classpath;
    }
    if (function_exists("apc_fetch")) {
        $classpath = apc_fetch("fw:root:autoload:map:1397705849");
        if ($classpath) {
            return $classpath;
        }
        $classpath = getClassMapDef();
        apc_store("fw:root:autoload:map:1397705849", $classpath);
    } else {
        if (function_exists("eaccelerator_get")) {
            $classpath = eaccelerator_get("fw:root:autoload:map:1397705849");
            if ($classpath) {
                return $classpath;
            }
            $classpath = getClassMapDef();
            eaccelerator_put("fw:root:autoload:map:1397705849", $classpath);
        } else {
            $classpath = getClassMapDef();
        }
    }
    return $classpath;
}
Ejemplo n.º 8
0
 /**
  */
 public function set($key, $data, $lifetime = 0)
 {
     $key = $this->_params['prefix'] . $key;
     if (eaccelerator_put($key . '_expire', time(), $lifetime)) {
         eaccelerator_put($key, $data, $lifetime);
     }
 }
 /**
  * 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)
 {
     eaccelerator_lock(md5($this->identifier . $key));
     $check = eaccelerator_put(md5($this->identifier . $key), $value, intval($ttl));
     eaccelerator_unlock(md5($this->identifier . $key));
     return $check;
 }
 /**
  * add
  * @param string $key
  * @param string|array|object $value
  * @param int $ttl
  * @param string $tableName
  * @param resource $connectionResource
  * @return boolean
  */
 public function add($key, $value, $ttl = 0, $tableName = '', $connectionResource = null)
 {
     $connectionResource = null;
     $value = serialize($value);
     //eAccelerator doesn't serialize object
     return eaccelerator_put($this->getRealKey($tableName, $key), $value, $ttl);
 }
Ejemplo n.º 11
0
 public function set($key, $value, $ttl)
 {
     $expires = $_SERVER['REQUEST_TIME'] + $ttl;
     // prepend the application expiration time to the value and save
     // the value to cache. the "real" timeout is far in the future.
     eaccelerator_put($key, "{$expires}:{$value}", 3600);
     // 1 hour
 }
Ejemplo n.º 12
0
 public function setMulti($items, $ttl = 0)
 {
     $status = FALSE;
     foreach ($items as $key => $value) {
         $status = eaccelerator_put($key, $value, $ttl);
     }
     return $status;
 }
Ejemplo n.º 13
0
 /**
  * 设置一个缓存变量
  *
  * @access public
  *
  * @param string $key 缓存Key
  * @param mixed $value 缓存内容
  * @param int $expire 缓存时间(秒)
  *
  * @return boolean
  */
 public function set($key, $value, $expire = null)
 {
     //参数分析
     if (!$key) {
         return false;
     }
     $expire = is_null($expire) ? $this->_defaultOptions['expire'] : $expire;
     return eaccelerator_put($key, $value, $expire);
 }
 function put($name, $data, $ttl = 604800)
 {
     $ttl = (int) $ttl ? (int) $ttl : 604800;
     if (eaccelerator_lock($this->key . $name)) {
         eaccelerator_put($this->key . $name, serialize($data), $ttl);
         eaccelerator_unlock($this->key . $name);
     }
     $this->vars[$name] = $data;
 }
Ejemplo n.º 15
0
 public function set($key, $value, $type = '', $ttl = SESSION_EXPIRE)
 {
     $this->type = $type;
     $name = $this->_key($key);
     eaccelerator_lock($name);
     if (eaccelerator_put($name, $value, $ttl)) {
         return true;
     }
     return false;
 }
Ejemplo n.º 16
0
 public function set($key, $value, $type = "", $ttl = SESSION_EXPIRE)
 {
     $this->type = $type;
     $name = $this->_key($key);
     eaccelerator_lock($name);
     if (eaccelerator_put($name, $value, $ttl)) {
         return TRUE;
     }
     return FALSE;
 }
Ejemplo n.º 17
0
 /**
 +----------------------------------------------------------
 * 写入缓存
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param string $name 缓存变量名
 * @param mixed $value  存储数据
 +----------------------------------------------------------
 * @return boolen
 +----------------------------------------------------------
 */
 public function set($name, $value, $ttl = null)
 {
     N('cache_write', 1);
     if (isset($ttl) && is_int($ttl)) {
         $expire = $ttl;
     } else {
         $expire = $this->expire;
     }
     eaccelerator_lock($name);
     return eaccelerator_put($name, $value, $expire);
 }
Ejemplo n.º 18
0
 public function set($key, $val, $life_time = null)
 {
     if ($life_time === null) {
         $life_time = $this->life_time;
     }
     if (DEBUG) {
         \Lysine\logger('cache')->debug('Eaccelerator set key ' . (is_array($key) ? implode(',', $key) : $key) . ' with life_time ' . $life_time);
     }
     $key = $this->makeKey($key);
     return eaccelerator_put($key, $val, $life_time);
 }
Ejemplo n.º 19
0
 /**
  * Adds a new item that is to be cached
  *
  * @param string $key
  * @param mixed $data
  * @param bool $overwrite
  * @return bool
  */
 public function add($key, $data, $overwrite = false)
 {
     if ($overwrite == false) {
         if (eaccelerator_get($key) != null) {
             return false;
         } else {
             return eaccelerator_put($key, serialize($data), $this->ttl());
         }
     } else {
         return eaccelerator_put($key, serialize($data), $this->ttl());
     }
 }
 function put($name, $data, $ttl = 604800)
 {
     $ttl = (int) $ttl ? (int) $ttl : 604800;
     $expires = gmtime() + $ttl;
     eaccelerator_put($this->key . $name, serialize($data), $expires);
     /*if (eaccelerator_lock($this->key.$name))
     		{
     			eaccelerator_put($this->key.$name, serialize($data), $expires);
     			eaccelerator_unlock($this->key.$name);
     		}*/
     $this->vars[$name] = $data;
 }
Ejemplo n.º 21
0
 /**
  * Sets a value in the cache for the specified key.
  *
  * @param string The key name
  * @param string The content to put in cache
  * @param int The life time to keep the content in the cache
  *
  * @return boolean true if ok
  */
 public static function set($key, $value, $lifeTime = 0)
 {
     switch (self::cacher()) {
         case 'apc':
             return apc_store(self::getPrefix() . $key, $value, $lifeTime);
         case 'xcache':
             return xcache_set(self::getPrefix() . $key, $value, $lifeTime);
         case 'eaccelerator':
             return eaccelerator_put(self::getPrefix() . $key, serialize($value), $lifeTime);
     }
     return false;
 }
Ejemplo n.º 22
0
 /**
  * Write to cache
  *
  * @param string $name
  * @param mixed $value
  * @param array $tags
  * @param int $ttl
  */
 public function write($name, $value, $tags = NULL, $ttl = NULL)
 {
     $name = $this->prepareKey($name);
     $data = array('value' => $value);
     if ($tags) {
         $data['tags'] = $tags;
         foreach ($tags as $tag) {
             $this->write('tags/' . $tag, '', array());
         }
     }
     $this->stats->write++;
     eaccelerator_put($name, $data, $ttl ? time() + $ttl : 0);
 }
Ejemplo n.º 23
0
function setRamCache($key, $data, $depo)
{
    if ($depo == 'ram_eaccelerator') {
        return eaccelerator_put($key, $data);
    }
    if ($depo == 'ram_xcache') {
        return xcache_set($key, $data);
    }
    if ($depo == 'ram_memcache') {
        $memcache_obj = memcache_connect('127.0.0.1', '11211');
        return memcache_set($memcache_obj, $key, $data, 0, 86400);
    }
    return false;
}
Ejemplo n.º 24
0
 /**
  * write template to cache
  *
  * @access   public
  * @param	string		cache key
  * @param	array		templates to store
  * @return   boolean		true on success
  */
 function write($key, $templates)
 {
     if (!function_exists('eaccelerator_lock')) {
         return false;
     }
     eaccelerator_lock($key);
     if ($this->getParam('lifetime') == 'auto') {
         eaccelerator_put($key, serialize($templates));
     } else {
         eaccelerator_put($key, serialize($templates), $this->getParam('lifetime') * 60);
     }
     eaccelerator_unlock($key);
     return true;
 }
Ejemplo n.º 25
0
 /**
 +----------------------------------------------------------
 * 写入缓存
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param string $name 缓存变量名
 * @param mixed $value  存储数据
 * @param integer $expire  有效时间(秒)
 +----------------------------------------------------------
 * @return boolen
 +----------------------------------------------------------
 */
 public function set($name, $value, $expire = null)
 {
     N('cache_write', 1);
     if (is_null($expire)) {
         $expire = $this->options['expire'];
     }
     eaccelerator_lock($name);
     if (eaccelerator_put($name, $value, $expire)) {
         if ($this->options['length'] > 0) {
             // 记录缓存队列
             $this->queue($name);
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 26
0
function setRamCache($key, $data, $depo, $ttl = 86400)
{
    if ($depo == 'ram_eaccelerator') {
        return eaccelerator_put($key, $data, $ttl);
    }
    if ($depo == 'ram_xcache') {
        return xcache_set($key, $data, $ttl);
    }
    if ($depo == 'ram_memcache') {
        $memcache_obj = new Memcache();
        if ($memcache_obj->connect(getMemcacheHost(), getMemcachePort())) {
            $result = $memcache_obj->set($key, $data, 0, $ttl);
            $memcache_obj->close();
        }
        return $result;
    }
    return false;
}
Ejemplo n.º 27
0
 public function set($key, $value = "", $ttl = 300, $mode = 0)
 {
     if (empty($value)) {
         return eaccelerator_rm($key);
     } else {
         eaccelerator_lock($key);
         switch ($mode) {
             case 1:
                 return eaccelerator_cache_output($key, $value, $ttl);
                 break;
             case 2:
                 return eaccelerator_cache_result($key, $value, $ttl);
                 break;
             default:
                 return eaccelerator_put($key, $value, $ttl);
         }
         eaccelerator_unlock($key);
     }
 }
Ejemplo n.º 28
0
 /**
  * Stores a value identified by a key in cache.
  * This is the implementation of the method declared in the parent class.
  *
  * @param string $key the key identifying the value to be cached
  * @param string $value the value to be cached
  * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
  * @return boolean true if the value is successfully stored into cache, false otherwise
  */
 protected function setValue($key, $value, $expire)
 {
     return eaccelerator_put($key, $value, $expire);
 }
Ejemplo n.º 29
0
 /**
  * Write session data to the SessionHandler backend.
  *
  * @param   string  $id            The session identifier.
  * @param   string  $session_data  The session data.
  *
  * @return  boolean  True on success, false otherwise.
  *
  * @since   11.1
  */
 public function write($id, $session_data)
 {
     $sess_id = 'sess_' . $id;
     return eaccelerator_put($sess_id, $session_data, ini_get("session.gc_maxlifetime"));
 }
Ejemplo n.º 30
0
function cache_put_data($key, $value, $ttl = 120)
{
    global $boardurl, $sourcedir, $modSettings, $memcached;
    global $cache_hits, $cache_count, $db_show_debug;
    if (empty($modSettings['cache_enable']) && !empty($modSettings)) {
        return;
    }
    $cache_count = isset($cache_count) ? $cache_count + 1 : 1;
    if (isset($db_show_debug) && $db_show_debug === true) {
        $cache_hits[$cache_count] = array('k' => $key, 'd' => 'put', 's' => $value === null ? 0 : strlen(serialize($value)));
        $st = microtime();
    }
    $key = md5($boardurl . filemtime($sourcedir . '/Load.php')) . '-SMF-' . $key;
    $value = $value === null ? null : serialize($value);
    // The simple yet efficient memcached.
    if (function_exists('memcache_set') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') {
        // Not connected yet?
        if (empty($memcached)) {
            get_memcached_server();
        }
        if (!$memcached) {
            return;
        }
        memcache_set($memcached, $key, $value, 0, $ttl);
    } elseif (function_exists('eaccelerator_put')) {
        if (mt_rand(0, 10) == 1) {
            eaccelerator_gc();
        }
        if ($value === null) {
            @eaccelerator_rm($key);
        } else {
            eaccelerator_put($key, $value, $ttl);
        }
    } elseif (function_exists('mmcache_put')) {
        if (mt_rand(0, 10) == 1) {
            mmcache_gc();
        }
        if ($value === null) {
            @mmcache_rm($key);
        } else {
            mmcache_put($key, $value, $ttl);
        }
    } elseif (function_exists('apc_store')) {
        // An extended key is needed to counteract a bug in APC.
        if ($value === null) {
            apc_delete($key . 'smf');
        } else {
            apc_store($key . 'smf', $value, $ttl);
        }
    } elseif (function_exists('output_cache_put')) {
        output_cache_put($key, $value);
    }
    if (isset($db_show_debug) && $db_show_debug === true) {
        $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
    }
}