You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laminas Cache报错:配置需含'adapter'键,求排查解决

解决Laminas Cache的"Configuration must contain a 'adapter' key"致命错误

错误信息

PHP message: PHP Fatal error: Uncaught InvalidArgumentException:
Configuration must contain a "adapter" key. in
/var/www/test/vendor/laminas/laminas-cache/src/Service/StorageAdapterFactory.php:79

你的配置

'caches' => [
    'FilesystemCache' => [
        'adapter' => [
            'name' => Filesystem::class,
            'options' => [
                // Store cached data in this directory.
                'cache_dir' => './data/cache',
                // Store cached data for 1 hour.
                'ttl' => 60 * 60 * 1
            ],
        ],
        'plugins' => [
            [
                'name' => 'serializer',
                'options' => [
                ],
            ],
        ],
    ],
],

问题原因及解决方法

1. 配置结构不符合Laminas Cache预期

你当前把options嵌套在adapter数组中,但Laminas推荐的StorageCacheAbstractServiceFactory创建缓存实例时,要求adapter为适配器类名/别名字符串,options与adapter同级。修正后的配置如下:

// 必须先引入命名空间
use Laminas\Cache\Storage\Adapter\Filesystem;

'caches' => [
    'FilesystemCache' => [
        'adapter' => Filesystem::class,
        'options' => [
            'cache_dir' => './data/cache',
            'ttl' => 60 * 60 * 1
        ],
        'plugins' => [
            'serializer' => []
        ],
    ],
],

2. 缺少Filesystem适配器依赖

如果还未安装文件系统适配器包,执行以下命令补全依赖:

composer require laminas/laminas-cache-storage-adapter-filesystem

3. 命名空间未引入

确保global.php顶部添加了Filesystem类的命名空间引用,否则Filesystem::class会被解析为当前命名空间下的不存在类,导致配置读取异常。

内容的提问来源于stack exchange,提问作者ViceStar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 00:25:17