1

I am getting this error and due to the updated version of Laminas cache component. The code below works fine on previous versions of Laminas framework.

use Laminas\Session\Storage\SessionArrayStorage;
use Laminas\Session\Validator\RemoteAddr;
use Laminas\Session\Validator\HttpUserAgent;
use Laminas\Cache\Storage\Adapter\Filesystem;

return [
    // Session configuration.
    'session_config' => [
        'cookie_lifetime'     => 60*60*1, // Session cookie will expire in 1 hour.
        'gc_maxlifetime'      => 60*60*24*30, // How long to store session data on server (for 1 month).        
    ],
    // Session manager configuration.
    'session_manager' => [
        // Session validators (used for security).
        'validators' => [
            RemoteAddr::class,
            HttpUserAgent::class,
        ]
    ],
    // Session storage configuration.
    'session_storage' => [
        'type' => SessionArrayStorage::class
    ],
    // Cache configuration.
    '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' => [                        
                    ],
                ],
            ],
        ],
    ],
    
];

I don't know why I'm getting this error: An error occurred An error occurred during execution; please try again later. Additional information: Laminas\ServiceManager\Exception\ServiceNotCreatedException File: D:\xampp\htdocs\pr360gh\vendor\laminas\laminas-servicemanager\src\ServiceManager.php:622 Message: Service with name "FilesystemCache" could not be created. Reason: Configuration must contain a "adapter" key.

What I'm I not doing right?

dino
  • 23
  • 4

1 Answers1

0

There have been some changes for the version 3 of laminas-cache. Registering the different cache adapters by AdapterClass was removed. Looks like your naming is wrong for the filesystem cache adapter.

return [
    ...
    'caches' => [
        'filesystem' => [
            'adapter' => [
                ...
            ],
        ],
    ],
    ...
];

Just try filesystem instead of FilesystemCache. For further informations have a look at these resources:

The first Basic Usage Example for adapters shows the correct naming for the filesystem adapter.

Marcel
  • 4,854
  • 1
  • 14
  • 24