mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进Cache类 及 驱动 改进Connection类及驱动
This commit is contained in:
22
library/think/cache/driver/Memcache.php
vendored
22
library/think/cache/driver/Memcache.php
vendored
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user