缓存类增加tag方法 用于缓存标签设置 clear方法支持清除某个缓存标签的数据

This commit is contained in:
thinkphp
2016-08-17 16:12:49 +08:00
parent 65053bc1a5
commit 631334b31e
10 changed files with 283 additions and 26 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' => '',
@@ -78,8 +79,12 @@ class Xcache
if (is_null($expire)) {
$expire = $this->options['expire'];
}
if ($this->tag && !$this->has($name)) {
$first = true;
}
$name = $this->options['prefix'] . $name;
if (xcache_set($name, $value, $expire)) {
isset($first) && $this->setTagItem($name);
return true;
}
return false;
@@ -125,10 +130,19 @@ class Xcache
/**
* 清除缓存
* @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);
}
return true;
}
if (function_exists('xcache_unset_by_prefix')) {
return xcache_unset_by_prefix($this->options['prefix']);
} else {