内核更新
This commit is contained in:
41
core/library/think/cache/driver/Xcache.php
vendored
41
core/library/think/cache/driver/Xcache.php
vendored
@@ -11,13 +11,14 @@
|
||||
|
||||
namespace think\cache\driver;
|
||||
|
||||
use think\cache\Driver;
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* Xcache缓存驱动
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
class Xcache
|
||||
class Xcache extends Driver
|
||||
{
|
||||
protected $options = [
|
||||
'prefix' => '',
|
||||
@@ -48,8 +49,8 @@ class Xcache
|
||||
*/
|
||||
public function has($name)
|
||||
{
|
||||
$name = $this->options['prefix'] . $name;
|
||||
return xcache_isset($name);
|
||||
$key = $this->getCacheKey($name);
|
||||
return xcache_isset($key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,8 +62,8 @@ class Xcache
|
||||
*/
|
||||
public function get($name, $default = false)
|
||||
{
|
||||
$name = $this->options['prefix'] . $name;
|
||||
return xcache_isset($name) ? xcache_get($name) : $default;
|
||||
$key = $this->getCacheKey($name);
|
||||
return xcache_isset($key) ? xcache_get($key) : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,8 +79,12 @@ class Xcache
|
||||
if (is_null($expire)) {
|
||||
$expire = $this->options['expire'];
|
||||
}
|
||||
$name = $this->options['prefix'] . $name;
|
||||
if (xcache_set($name, $value, $expire)) {
|
||||
if ($this->tag && !$this->has($name)) {
|
||||
$first = true;
|
||||
}
|
||||
$key = $this->getCacheKey($name);
|
||||
if (xcache_set($key, $value, $expire)) {
|
||||
isset($first) && $this->setTagItem($key);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -94,8 +99,8 @@ class Xcache
|
||||
*/
|
||||
public function inc($name, $step = 1)
|
||||
{
|
||||
$name = $this->options['prefix'] . $name;
|
||||
return xcache_inc($name, $step);
|
||||
$key = $this->getCacheKey($name);
|
||||
return xcache_inc($key, $step);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,8 +112,8 @@ class Xcache
|
||||
*/
|
||||
public function dec($name, $step = 1)
|
||||
{
|
||||
$name = $this->options['prefix'] . $name;
|
||||
return xcache_dec($name, $step);
|
||||
$key = $this->getCacheKey($name);
|
||||
return xcache_dec($key, $step);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,16 +124,26 @@ class Xcache
|
||||
*/
|
||||
public function rm($name)
|
||||
{
|
||||
return xcache_unset($this->options['prefix'] . $name);
|
||||
return xcache_unset($this->getCacheKey($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除缓存
|
||||
* @access public
|
||||
* @param string $tag 标签名
|
||||
* @return boolean
|
||||
*/
|
||||
public function clear()
|
||||
public function clear($tag = null)
|
||||
{
|
||||
if ($tag) {
|
||||
// 指定标签清除
|
||||
$keys = $this->getTagItem($tag);
|
||||
foreach ($keys as $key) {
|
||||
xcache_unset($key);
|
||||
}
|
||||
$this->rm('tag_' . md5($tag));
|
||||
return true;
|
||||
}
|
||||
if (function_exists('xcache_unset_by_prefix')) {
|
||||
return xcache_unset_by_prefix($this->options['prefix']);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user