改进Cache类 及 驱动 改进Connection类及驱动

This commit is contained in:
thinkphp
2016-05-05 16:32:47 +08:00
parent fd5447fc4f
commit 855c2c75da
31 changed files with 147 additions and 599 deletions

View File

@@ -17,9 +17,8 @@ use think\Cache;
* Secache缓存驱动
* @author liu21st <liu21st@gmail.com>
*/
class Secache implements CacheInterface
class Secache
{
protected $handler = null;
protected $options = [
'project' => '',
@@ -55,7 +54,6 @@ class Secache implements CacheInterface
*/
public function get($name)
{
Cache::$readTimes++;
$name = $this->options['prefix'] . $name;
$key = md5($name);
$this->handler->fetch($key, $return);
@@ -72,30 +70,9 @@ class Secache implements CacheInterface
*/
public function set($name, $value)
{
Cache::$writeTimes++;
$name = $this->options['prefix'] . $name;
$key = md5($name);
if ($result = $this->handler->store($key, $value)) {
if ($this->options['length'] > 0) {
// 记录缓存队列
$queue = $this->handler->fetch(md5('__info__'));
if (!$queue) {
$queue = [];
}
if (false === array_search($key, $queue)) {
array_push($queue, $key);
}
if (count($queue) > $this->options['length']) {
// 出列
$key = array_shift($queue);
// 删除缓存
$this->handler->delete($key);
}
$this->handler->store(md5('__info__'), $queue);
}
}
return $result;
return $this->handler->store($key, $value);
}
/**