本文整理汇总了PHP中xcache_set函数的典型用法代码示例。如果您正苦于以下问题:PHP xcache_set函数的具体用法?PHP xcache_set怎么用?PHP xcache_set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xcache_set函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set
/**
* 写入缓存
* @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: set
/**
* 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: set
public function set($key, $value, $ttl = 0)
{
if ($ttl > 0) {
return xcache_set($key, $value, $ttl);
}
return xcache_set($key, $value);
}
示例4: set
/**
*/
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: set
public function set($key, $value, $expire = 86400)
{
if (!$key) {
return false;
}
return xcache_set($key, $value, $expire);
}
示例6: set
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: set
/**
* 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: set
/**
* 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: store
public function store($key, $value)
{
if (xcache_set($key, $value)) {
xcache_inc('__known_xcache_size', strlen($value));
}
return false;
}
示例10: set
function set($key, $value, $ttl)
{
if (!ini_get('xcache.var_size')) {
return;
}
@xcache_set($key, serialize($value), $ttl);
}
示例11: get
/**
* 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: write
/**
* 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: set
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: set
/**
* 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: set
/**
* @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);
}