x_mier/think-cache 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

x_mier/think-cache

最新稳定版本:v1.0.1

Composer 安装命令:

composer require x_mier/think-cache

包简介

Thinkphp8提取的Think-cache组件

README 文档

README

由于think-cache官方放弃了更新,且使用ThinkORM做缓存如果使用webman的Cache类,tag功能无法使用。

故本项目提取自ThinkPHP8最新的Cache模块,完美适配ThinkORM查询缓存的tag和其他所有方法。

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

安装

composer require x_mier/think-cache

配置文件

配置文件参考文档,如下所示,将配置命名为cache.php,存放在webman项目的config目录下

// 如果ThinkORM需要使用缓存,请输入以下代码,或者在其他合适的地方引入
\think\facade\Db::setCache(new \think\Cache\CacheManager());

return [
    'default'    =>    'redis',
    'stores'    =>    [
        // 文件缓存
        'file'   =>  [
            // 驱动方式
            'type'   => 'file',
            // 设置不同的缓存保存目录 __DIR__ . '/../runtime/file/'
            'path'   => runtime_path() . '/file/',
        ],  
        // redis缓存
        'redis'   =>  [
            // 驱动方式
            'type'   => 'redis',
            // 服务器地址
            'host'       => '127.0.0.1',
            // Thinkphp官方没有这个参数,由于生成的tag键默认不过期
            // 如果tag键数量很大,避免长时间占用内存,可以设置一个超过其他缓存的过期时间
            'tag_expire' => 86400 * 30,
            // tag前缀
            'tag_prefix' => 'tag_'
        ],  
    ],
];

使用说明

use think\facade\Cache;

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

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

统计信息

  • 总下载量: 28
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-24