php - zend Framework 2 - 缓存配置文件

标签 php zend-framework2 zend-framework-modules

我正在尝试在 zend Framework 2 中启用配置文件的缓存:

module.config.php(服务的一部分):

 'service_manager' => array(
        'factories' => array(
            'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
            'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
            'doctrine.cache.mycache' => function ($sm) {
                 $cache = new \Doctrine\Common\Cache\MemcacheCache();
                     $memcache = new \Memcache();
                     $memcache->connect('localhost', 11211);
                     $cache->setMemcache($memcache);
                 return $cache;
         },
        ),
    ),

application.config.php(启用配置缓存的一部分):

'module_listener_options' => array(
        'module_paths' => array(
            './module',
            './vendor',
        ),
        'config_glob_paths' => array(
            'config/autoload/{,*.}{global,local}.php',
        ),
        'config_cache_enabled' => true,
        'config_cache_key' => md5('config'),
        'module_map_cache_enabled' => true,
        'module_map_cache_key' => md5('module_map'),
        'cache_dir' => "./data/cache/modulecache",
    ),

这是我得到的错误:

 Fatal error: Call to undefined method Closure::__set_state()

谢谢。

最佳答案

如果配置文件包含匿名函数(在您的情况下为 doctrine.cache.mycache 的值),则无法缓存它们。您需要将该部分从配置文件中移出并移入您的 Module.php 类的 getServiceConfig() 中。这应该可以解决问题。

关于php - zend Framework 2 - 缓存配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27251931/

相关文章:

php - zf2 为什么要在模块配置中的可调用数组中添加 Controller

zend-framework - Zend Framework 模块应该包含哪些功能?

php - 如何在 PHP 中使用其他语言的 echo 或 print

php - 如果 p 标签后面跟着任何其他标签,xpath 不会返回文本

php - 平均评级值计数

javascript - 当 sql 返回错误时,Jquery Ajax 显示错误 500

php - Zend 框架 2 'quote_identifiers' => false

php - 如何使用 zend framework 2 运行 cron 作业

zend-framework2 - zf2中的loadModules.post是一个函数吗?