提取自ThinkPHP8.0最新缓存插件think-cache

v1.0.9 版本
2024-04-25 版本更新时间
51 安装
3 star

说明

由于think-cache官方放弃了更新,且不支持php 8及以上,当使用ThinkORM做缓存时,如果使用webman的Cache类,tag功能无法使用。

故本项目提取自ThinkPHP 8最新的Cache模块,完美适配ThinkORM的缓存操作,以及字段缓存,tag和其他所有方法。

详细情况请查看ThinkPHP8官方缓存文档

安装

composer require bilulanlv/think-cache

配置说明

配置文件自动安装在 config/plugin/bilulanlv/think-cache/app.php
详细配置可参考ThinkPHP8官方缓存文档

// think-cache官方没有这个参数,由于生成的tag键默认不过期,如果tag键数量很大,避免长时间占用内存,可以设置一个超过其他缓存的过期时间,0为不设置。
'tag_expire' => 86400 * 7,

使用说明

use Bilulanlv\ThinkCache\facade\ThinkCache;

ThinkCache::set('name', $value, 3600);
ThinkCache::remember('start_time', time());
ThinkCache::tag('tag')->set('name1','value1');
ThinkCache::tag('tag')->clear();

UserModel::where('id', 1)->cache($cache['key'], $cache['expire'], $cache['tag'])->find();