简体   繁体   中英

Laminas Cache config issue after updated to PHP 8.1 from zend3

I work on a project which is recently updated to Laminas and PHP 8.1 from Zend3 and PHP 7.4.

in config/autoload/global.php

  'caches' => require __DIR__ . '/caches.php',

and this is caches.php

$cacheDefault = [
    'adapter' => [
       'name'    => 'Memcached',
       'options' => [
        'servers' => Module::isRunningOnVM()
            ? ['127.0.0.1:11211']
            : Module::getMemcachedServersFromEnvironment(),
       ],
    ],
];

return [

   'cache_instrument_manager_search' => array_merge_recursive(
       $cacheDefault,
       [
        'adapter' => [
            'options' => [
                'namespace' => 'instrument_manager_search',
                'ttl'       => 20,
            ],
        ],
       ]
    ),

  'cache_weekly' => array_merge_recursive(
       $cacheDefault,
       [
           'adapter' => [
               'options' => [
                    'namespace' => 'weekly',
                   'ttl'       => 604800, // whole week
               ],
           ],
       ]
    ),
  ];

It worked well in zend 3. but after updating to Laminas and PHP8.1 I got this error

Laminas\ServiceManager\Exception\ServiceNotCreatedException

File:

/project/vendor/laminas/laminas-servicemanager/src/ServiceManager.php:620

Message:

Service with name "cache_instrument_manager_search" could not be created. Reason: Configuration must contain a "adapter" key.

I have changed it to

return [

   'cache_instrument_manager_search' => [
       'adapter' => 'Memcached',
       'options' => ['ttl' => 3600],
       'plugins' => [
           [
               'name' => 'exception_handler',
               'options' => [
                   'throw_exceptions' => false,
                ],
            ],
        ],
    ]
];

But Still has this error Laminas\ServiceManager\Exception\ServiceNotFoundException

File:

/project/vendor/laminas/laminas-servicemanager/src/ServiceManager.php:557

Message:

Unable to resolve service "Memcached" to a factory; are you certain you provided it during configuration?

I need help. I read documents in Laminas but still could not solve this.

I'm using Redis Cache and I had to add:

'Laminas\Cache\Storage\Adapter\Redis'

to my modules.config.php file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM