改进缓存标签的设置和删除

This commit is contained in:
thinkphp
2016-08-17 19:07:29 +08:00
parent 684c04849a
commit 90fc917b00
9 changed files with 112 additions and 78 deletions

View File

@@ -70,8 +70,8 @@ class Memcached extends Driver
*/
public function has($name)
{
$name = $this->options['prefix'] . $name;
return $this->handler->get($name) ? true : false;
$key = $this->getCacheKey($name);
return $this->handler->get($key) ? true : false;
}
/**
@@ -83,7 +83,7 @@ class Memcached extends Driver
*/
public function get($name, $default = false)
{
$result = $this->handler->get($this->options['prefix'] . $name);
$result = $this->handler->get($this->getCacheKey($name));
return false !== $result ? $result : $default;
}
@@ -103,10 +103,10 @@ class Memcached extends Driver
if ($this->tag && !$this->has($name)) {
$first = true;
}
$name = $this->options['prefix'] . $name;
$key = $this->getCacheKey($name);
$expire = 0 == $expire ? 0 : $_SERVER['REQUEST_TIME'] + $expire;
if ($this->handler->set($name, $value, $expire)) {
isset($first) && $this->setTagItem($name);
if ($this->handler->set($key, $value, $expire)) {
isset($first) && $this->setTagItem($key);
return true;
}
return false;
@@ -121,8 +121,8 @@ class Memcached extends Driver
*/
public function inc($name, $step = 1)
{
$name = $this->options['prefix'] . $name;
return $this->handler->increment($name, $step);
$key = $this->getCacheKey($name);
return $this->handler->increment($key, $step);
}
/**
@@ -134,9 +134,9 @@ class Memcached extends Driver
*/
public function dec($name, $step = 1)
{
$name = $this->options['prefix'] . $name;
$value = $this->handler->get($name) - $step;
$res = $this->handler->set($name, $value);
$key = $this->getCacheKey($name);
$value = $this->handler->get($key) - $step;
$res = $this->handler->set($key, $value);
if (!$res) {
return false;
} else {
@@ -152,10 +152,10 @@ class Memcached extends Driver
*/
public function rm($name, $ttl = false)
{
$name = $this->options['prefix'] . $name;
$key = $this->getCacheKey($name);
return false === $ttl ?
$this->handler->delete($name) :
$this->handler->delete($name, $ttl);
$this->handler->delete($key) :
$this->handler->delete($key, $ttl);
}
/**
@@ -170,6 +170,7 @@ class Memcached extends Driver
// 指定标签清除
$keys = $this->getTagItem($tag);
$this->handler->deleteMulti($keys);
$this->rm('tag_' . md5($tag));
return true;
}
return $this->handler->flush();