mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 15:02:47 +08:00
缓存类增加tag方法 用于缓存标签设置 clear方法支持清除某个缓存标签的数据
This commit is contained in:
18
library/think/cache/driver/Memcache.php
vendored
18
library/think/cache/driver/Memcache.php
vendored
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace think\cache\driver;
|
||||
|
||||
use think\cache\Driver;
|
||||
use think\Exception;
|
||||
|
||||
class Memcache
|
||||
class Memcache extends Driver
|
||||
{
|
||||
protected $handler = null;
|
||||
protected $options = [
|
||||
@@ -93,8 +94,12 @@ class Memcache
|
||||
if (is_null($expire)) {
|
||||
$expire = $this->options['expire'];
|
||||
}
|
||||
if ($this->tag && !$this->has($name)) {
|
||||
$first = true;
|
||||
}
|
||||
$name = $this->options['prefix'] . $name;
|
||||
if ($this->handler->set($name, $value, 0, $expire)) {
|
||||
isset($first) && $this->setTagItem($name);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -149,10 +154,19 @@ class Memcache
|
||||
/**
|
||||
* 清除缓存
|
||||
* @access public
|
||||
* @param string $tag 标签名
|
||||
* @return bool
|
||||
*/
|
||||
public function clear()
|
||||
public function clear($tag = null)
|
||||
{
|
||||
if ($tag) {
|
||||
// 指定标签清除
|
||||
$keys = $this->getTagItem($tag);
|
||||
foreach ($keys as $key) {
|
||||
$this->handler->delete($key);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return $this->handler->flush();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user