内核更新

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,7 +11,9 @@
namespace think\cache\driver;
class Memcached
use think\cache\Driver;
class Memcached extends Driver
{
protected $handler;
protected $options = [
@@ -68,8 +70,8 @@ class Memcached
*/
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;
}
/**
@@ -81,7 +83,7 @@ class Memcached
*/
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;
}
@@ -98,9 +100,13 @@ class Memcached
if (is_null($expire)) {
$expire = $this->options['expire'];
}
$name = $this->options['prefix'] . $name;
if ($this->tag && !$this->has($name)) {
$first = true;
}
$key = $this->getCacheKey($name);
$expire = 0 == $expire ? 0 : $_SERVER['REQUEST_TIME'] + $expire;
if ($this->handler->set($name, $value, $expire)) {
if ($this->handler->set($key, $value, $expire)) {
isset($first) && $this->setTagItem($key);
return true;
}
return false;
@@ -115,8 +121,8 @@ class Memcached
*/
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);
}
/**
@@ -128,9 +134,9 @@ class Memcached
*/
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 {
@@ -146,19 +152,27 @@ class Memcached
*/
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);
}
/**
* 清除缓存
* @access public
* @param string $tag 标签名
* @return bool
*/
public function clear()
public function clear($tag = null)
{
if ($tag) {
// 指定标签清除
$keys = $this->getTagItem($tag);
$this->handler->deleteMulti($keys);
$this->rm('tag_' . md5($tag));
return true;
}
return $this->handler->flush();
}
}