mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-05 22:52:49 +08:00
改进Cache类 及 驱动 改进Connection类及驱动
This commit is contained in:
23
library/think/cache/driver/File.php
vendored
23
library/think/cache/driver/File.php
vendored
@@ -17,7 +17,7 @@ use think\Cache;
|
||||
* 文件类型缓存类
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
class File implements CacheInterface
|
||||
class File
|
||||
{
|
||||
|
||||
protected $options = [
|
||||
@@ -98,7 +98,6 @@ class File implements CacheInterface
|
||||
if (!is_file($filename)) {
|
||||
return false;
|
||||
}
|
||||
Cache::$readTimes++;
|
||||
$content = file_get_contents($filename);
|
||||
if (false !== $content) {
|
||||
$expire = (int) substr($content, 8, 12);
|
||||
@@ -129,7 +128,6 @@ class File implements CacheInterface
|
||||
*/
|
||||
public function set($name, $value, $expire = null)
|
||||
{
|
||||
Cache::$writeTimes++;
|
||||
if (is_null($expire)) {
|
||||
$expire = $this->options['expire'];
|
||||
}
|
||||
@@ -142,25 +140,6 @@ class File implements CacheInterface
|
||||
$data = "<?php\n//" . sprintf('%012d', $expire) . $data . "\n?>";
|
||||
$result = file_put_contents($filename, $data);
|
||||
if ($result) {
|
||||
if ($this->options['length'] > 0) {
|
||||
// 记录缓存队列
|
||||
$queue_file = dirname($filename) . '/__info__.php';
|
||||
$queue = unserialize(file_get_contents($queue_file));
|
||||
if (!$queue) {
|
||||
$queue = [];
|
||||
}
|
||||
if (false === array_search($name, $queue)) {
|
||||
array_push($queue, $name);
|
||||
}
|
||||
|
||||
if (count($queue) > $this->options['length']) {
|
||||
// 出列
|
||||
$key = array_shift($queue);
|
||||
// 删除缓存
|
||||
$this->unlink($this->filename($key));
|
||||
}
|
||||
file_put_contents($queue_file, serialize($queue));
|
||||
}
|
||||
clearstatcache();
|
||||
return true;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user