内核更新

This commit is contained in:
2016-08-19 11:53:45 +08:00
parent 63f95a8ee9
commit 707ebdf51d
20 changed files with 505 additions and 154 deletions

View File

@@ -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 {