webman 默认的 Cache 为 symfony/cache 怎么配置成文件驱动而非 redis

yookey

问题描述

采用 webman 默认安装了 symfony/cache 后好像只能用 redis 驱动,请问下大佬们怎么能配置成 文件驱动 形式,或者有没有类似 ThinkPHP8 中的 Cache 组件:能配置成文件驱动,也能配置为 redis 驱动, 并且能支持 >= PHP8.1,谢谢!

为此你搜索到了哪些方案及不适用的原因

ThinkCache 但不支持 PHP 8.1

158 3 0
3个回答

胡桃

app/bootstrap/FilesystemCache.php

<?php
declare(strict_types=1);

namespace app\bootstrap;

use support\Cache;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Psr16Cache;

class FilesystemCache
{
    public static function start($worker): void
    {
        Cache::$instance = new Psr16Cache(new FilesystemAdapter(
            directory: runtime_path('cache'),
        ));
    }
}

config/bootstrap.php

<?php

return [
    support\bootstrap\Session::class,
    support\bootstrap\LaravelDb::class,
    \app\bootstrap\FilesystemCache::class,
];
  • yookey 5天前

    谢谢大佬,非常感谢,已经OK

walkor

回头我加个配置

  • yookey 5天前

    哈哈~~ 那更好了,紧随大佬脚步 ~

walkor

增加了file和array驱动
老用户需要升级webman-framework,自行创建 config/cache.php
参考文档 https://www.workerman.net/doc/webman/db/cache.html

  • yookey 3天前

    哈哈~~ 大佬高效率,赞!

×
🔝