改进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

@@ -14,7 +14,7 @@ namespace think\cache\driver;
use think\Cache;
use think\Exception;
class Memcache implements CacheInterface
class Memcache
{
protected $handler = null;
protected $options = [
@@ -65,7 +65,6 @@ class Memcache implements CacheInterface
*/
public function get($name)
{
Cache::$readTimes++;
return $this->handler->get($this->options['prefix'] . $name);
}
@@ -79,30 +78,11 @@ class Memcache implements CacheInterface
*/
public function set($name, $value, $expire = null)
{
Cache::$writeTimes++;
if (is_null($expire)) {
$expire = $this->options['expire'];
}
$name = $this->options['prefix'] . $name;
if ($this->handler->set($name, $value, 0, $expire)) {
if ($this->options['length'] > 0) {
// 记录缓存队列
$queue = $this->handler->get('__info__');
if (!$queue) {
$queue = [];
}
if (false === array_search($name, $queue)) {
array_push($queue, $name);
}
if (count($queue) > $this->options['length']) {
// 出列
$key = array_shift($queue);
// 删除缓存
$this->handler->delete($key);
}
$this->handler->set('__info__', $queue);
}
return true;
}
return false;