内核更新

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,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 = [
@@ -63,8 +64,8 @@ class Memcache
*/
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;
}
/**
@@ -76,7 +77,7 @@ class Memcache
*/
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;
}
@@ -93,8 +94,12 @@ class Memcache
if (is_null($expire)) {
$expire = $this->options['expire'];
}
$name = $this->options['prefix'] . $name;
if ($this->handler->set($name, $value, 0, $expire)) {
if ($this->tag && !$this->has($name)) {
$first = true;
}
$key = $this->getCacheKey($name);
if ($this->handler->set($key, $value, 0, $expire)) {
isset($first) && $this->setTagItem($key);
return true;
}
return false;
@@ -109,8 +114,8 @@ class Memcache
*/
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);
}
/**
@@ -122,9 +127,9 @@ class Memcache
*/
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 {
@@ -140,19 +145,29 @@ class Memcache
*/
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);
foreach ($keys as $key) {
$this->handler->delete($key);
}
$this->rm('tag_' . md5($tag));
return true;
}
return $this->handler->flush();
}
}