webman使用tp的cahce缓存器是不是不会自动清除?

楚羽幽

tp的cache缓存时间过期了是不是不会自动清除呀? 我发现我设置了时间过期,缓存文件依然还是存在的

1086 1 0
1个回答

banro512

缓存过期删除原理:是在下一次获取此缓存时,先判断该缓存是否过期,如果过期,此时再删除。并非自动清除,和webman无关,tp里也是如此
think-cache关键代码

    /**
     * 读取缓存
     * @access public
     * @param  string $name 缓存变量名
     * @param  mixed  $default 默认值
     * @return mixed
     */
    public function get($name, $default = null)
    {
        $this->readTimes++;

        $filename = $this->getCacheKey($name);

        if (!is_file($filename)) {
            return $default;
        }

        $content      = file_get_contents($filename);
        $this->expire = null;

        if (false !== $content) {
            $expire = (int) substr($content, 8, 12);
           ** if (0 != $expire && time() > filemtime($filename) + $expire) {**
                //缓存过期删除缓存文件
                $this->unlink($filename);
                return $default;
            }

            $this->expire = $expire;
            $content      = substr($content, 32);

            if ($this->options['data_compress'] && function_exists('gzcompress')) {
                //启用数据压缩
                $content = gzuncompress($content);
            }
            return $this->unserialize($content);
        } else {
            return $default;
        }
    }

你可以尝试再获取下这个缓存,然后查看缓存文件是否已删除

年代过于久远,无法发表回答
🔝