内核更新
This commit is contained in:
46
core/library/think/cache/driver/Wincache.php
vendored
46
core/library/think/cache/driver/Wincache.php
vendored
@@ -11,19 +11,22 @@
|
||||
|
||||
namespace think\cache\driver;
|
||||
|
||||
use think\cache\Driver;
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* Wincache缓存驱动
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
class Wincache
|
||||
class Wincache extends Driver
|
||||
{
|
||||
protected $options = [
|
||||
'prefix' => '',
|
||||
'expire' => 0,
|
||||
];
|
||||
|
||||
protected $tag;
|
||||
|
||||
/**
|
||||
* 架构函数
|
||||
* @param array $options 缓存参数
|
||||
@@ -48,8 +51,8 @@ class Wincache
|
||||
*/
|
||||
public function has($name)
|
||||
{
|
||||
$name = $this->options['prefix'] . $name;
|
||||
return wincache_ucache_exists($name);
|
||||
$key = $this->getCacheKey($name);
|
||||
return wincache_ucache_exists($key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,8 +64,8 @@ class Wincache
|
||||
*/
|
||||
public function get($name, $default = false)
|
||||
{
|
||||
$name = $this->options['prefix'] . $name;
|
||||
return wincache_ucache_exists($name) ? wincache_ucache_get($name) : $default;
|
||||
$key = $this->getCacheKey($name);
|
||||
return wincache_ucache_exists($key) ? wincache_ucache_get($key) : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,8 +81,12 @@ class Wincache
|
||||
if (is_null($expire)) {
|
||||
$expire = $this->options['expire'];
|
||||
}
|
||||
$name = $this->options['prefix'] . $name;
|
||||
if (wincache_ucache_set($name, $value, $expire)) {
|
||||
$key = $this->getCacheKey($name);
|
||||
if ($this->tag && !$this->has($name)) {
|
||||
$first = true;
|
||||
}
|
||||
if (wincache_ucache_set($key, $value, $expire)) {
|
||||
isset($first) && $this->setTagItem($key);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -94,8 +101,8 @@ class Wincache
|
||||
*/
|
||||
public function inc($name, $step = 1)
|
||||
{
|
||||
$name = $this->options['prefix'] . $name;
|
||||
return wincache_ucache_inc($name, $step);
|
||||
$key = $this->getCacheKey($name);
|
||||
return wincache_ucache_inc($key, $step);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,8 +114,8 @@ class Wincache
|
||||
*/
|
||||
public function dec($name, $step = 1)
|
||||
{
|
||||
$name = $this->options['prefix'] . $name;
|
||||
return wincache_ucache_dec($name, $step);
|
||||
$key = $this->getCacheKey($name);
|
||||
return wincache_ucache_dec($key, $step);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,16 +126,27 @@ class Wincache
|
||||
*/
|
||||
public function rm($name)
|
||||
{
|
||||
return wincache_ucache_delete($this->options['prefix'] . $name);
|
||||
return wincache_ucache_delete($this->getCacheKey($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除缓存
|
||||
* @access public
|
||||
* @param string $tag 标签名
|
||||
* @return boolean
|
||||
*/
|
||||
public function clear()
|
||||
public function clear($tag = null)
|
||||
{
|
||||
return;
|
||||
if ($tag) {
|
||||
$keys = $this->getTagItem($tag);
|
||||
foreach ($keys as $key) {
|
||||
wincache_ucache_delete($key);
|
||||
}
|
||||
$this->rm('tag_' . md5($tag));
|
||||
return true;
|
||||
} else {
|
||||
return wincache_ucache_clear();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user