我是 Zend Framework 的新手,我有一个问题。
我的 CMS 中有 20 个模块,所有模块都使用 APC 缓存适配器(在模块配置中定义),现在我想将此适配器更改为 Memcache。
有没有什么好的做法而不是改变所有的 config.module.php ?
我是 Zend Framework 的新手,我有一个问题。
我的 CMS 中有 20 个模块,所有模块都使用 APC 缓存适配器(在模块配置中定义),现在我想将此适配器更改为 Memcache。
有没有什么好的做法而不是改变所有的 config.module.php ?
如果您使用 DI/Service Manager 设置缓存/缓存适配器,那么您应该能够非常简单地通过更改 Service Manager 配置中的定义来更改它。
服务管理器配置:
'My\Cache' => function($sm){
$cache = \Zend\Cache\StorageFactory::factory(array(
'adapter' => 'filesystem',
'plugins' => array(
'exception_handler' => array('throw_exceptions' => FALSE),
'serializer'
)
));
$cache->setOptions(array(
'cache_dir' => './data/cache',
'ttl' => 60*60,
));
return $cache;
},
然后,您可以在 SM 中更改适配器和设置。所有模块都将使用服务管理器来使用缓存,因此它们不需要任何进一步的更改。
一些模块:
<?php $cache = $this->getServiceManager()->get('My\Cache'); ?>