Upgrading to Laminas-cache v3

Hello,

I upgraded my laminas-cache to 3.1.2 (from 2.13.2) with laminas-cache-storage-adapter-filesystem.

In my /config/autoload/global.php I have this configuration:

'caches' => [
        'cache1' => [
            'adapter' => [
                'name'     =>'filesystem',
                'options'  => [
                    'ttl' => 10800,
                    'cacheDir' => 'data/cache/cache1',
                    'dir_level' => 0,
                    'readable' => false,
                    'writable' => false,
                ]
            ],
            'plugins' => [
                'exception_handler' => [
                    'throw_exceptions' => false
                ],
                'Serializer'
            ],
        ],
        'cache2' => [
            'adapter' => [
                'name'     =>'filesystem',
                'options'  => [
                    'ttl' => 0,
                    'cacheDir' => 'data/cache/cache2',
                    'dir_level' => 0,
                    'readable' => false,
                    'writable' => false,
                ]
            ],
            'plugins' => [
                'exception_handler' => [
                    'throw_exceptions' => false
                ],
                'Serializer'
            ],
        ],
    ],

But I have this error:
Service with name "cache1" could not be created. Reason: Configuration must contain a "adapter" key.

There is the adapter key in cache1, what it is the problem please?

I anwser to mysleft, it can help others, here is the correct configuration:

'caches' => [
        'cache1' => [
            'adapter' => 'filesystem',
            'options' => [
                'ttl' => 10800,
                'cacheDir' => 'data/cache/cache1',
                'dir_level' => 0,
                'readable' => false,
                'writable' => false,
            ],
            'plugins' => [
                [
                    'name' => 'exception_handler',
                    'options' => [
                        'throw_exceptions' => false,
                    ],
                ],
            ],
        ],
        'cache2' => [
            'adapter' => 'filesystem',
            'options' => [
                'ttl' => 0,
                'cacheDir' => 'data/cache/cache2',
                'dir_level' => 0,
                'readable' => false,
                'writable' => false,
            ],
            'plugins' => [
                [
                    'name' => 'exception_handler',
                    'options' => [
                        'throw_exceptions' => false,
                    ],
                ],
            ],
        ],
    ],

See also in the documentation: Adapters - laminas-cache - Laminas Docs

1 Like

Thank you very much for the update @JulienH!
@froschdesign the link doesn’t show too much about this specific problem.
I was wondering if this change was documented?

I check the migration doc Migration to Version 3.0 - laminas-cache - Laminas Docs
but there is nothing about changed config in Laminas MVC configuration.

The configuration is identical for stand-alone use and in a laminas-mvc-based application:

// Via array configuration:
$cache = $storageFactory->createFromArrayConfiguration(
    [
        'adapter' => 'apcu',
        'options' => ['ttl' => 3600],
        'plugins' => [
            [
                'name'    => 'exception_handler',
                'options' => [
                    'throw_exceptions' => false,
                ],
            ],
        ],
    ]
);
return [
    'caches' => [
        'cache-example' => [
            'adapter' => 'apcu',
            'options' => ['ttl' => 3600],
            'plugins' => [
                [
                    'name'    => 'exception_handler',
                    'options' => [
                        'throw_exceptions' => false,
                    ],
                ],
            ],
        ],
    ],
];

See also:

You can use a CLI command for this. Follow the checklist in the migration guide:

Or follow the link in the checklist to the normalized array configuration example:

@froschdesign Thank you very much!

I had a hard time finding examples for the array configs in the global.php file.
That’s the case for all laminas components.

Usually, I find stand-alone examples as you posted above,
then play around until I figure out how to use them in the global.php config and laminas MVC codebase.

Do you maybe know any reference where I can usually find the documentation for the array(s) in the global.php file? global, local, or MVC-based app.
Like this case in laminas-cache, we have

'caches' => [
    'cache-name' => [ ... ]
]

But I didn’t find anything in the doc about these array keys.
Literally :slight_smile: try this google search link

Thanks!

Sorry for the late response. I had a lot of work.

Then please report this! :+1:t2:

(Idea: a page could then be created, for example, that is placed in each component for which a corresponding configuration exists.)

The entire documentation of laminas-cache needs a rewrite because a quick start tutorials is missing and also the descriptions for application integrations, including the configuration keys.

Hi, sorry for my late reply! I hope you will get the notification :slight_smile:
So, should I report this on GitHub, or would it be better to start a new thread on discourse about this topic? because it is related to all components, not sure if it is “just” a forgotten thing.

I have already created a project on GitHub, which will soon be publicly visible. But feel free to start a new thread and add your idea or wishes there.

It is not missing in all components but it should be found in a consistent place in the individual documentation.

1 Like