有人知道如何在zf2项目中缓存doctrine2实体吗?我找不到对此进行解释的教程或网站。我找不到任何开始定义实体文件缓存的信息。
你们中的一些人获得了工作链接或示例。
谢谢
最佳答案
你有两个选择
- 使用原则的 native 缓存,例如使用memcache (在内存缓存 block 中,您可以使用任何类型的学说支持的缓存,完整列表 cache drivers 可用)。
- 使用Zend/Cache/Storage的学说适配器来使用您在其他地方使用的另一个缓存; adapter is described在 DoctrineModule 文档中。
作为版本二的示例,我在模块中有类似以下配置的内容(实际上分布在各个配置文件中,因此我不能保证逐字复制粘贴有效)。
'services' => array(
'factories' => array(
// Wraps a ZF2 cache storage in a Doctrine compatible way
'doctrine.cache.zend.static.local' => function ($services) {
return new ZendStorageCache($services->get('cache.static.local'));
},
),
'caches' => array(
// A ZF2 cache, can be configured as you like
'cache.static.local' => array(
'adapter' => 'xcache',
'plugins' => array(
'exception_handler' => array(
'throw_exceptions' => false,
),
'serializer',
),
),
),
'doctrine' => array(
'configuration' => array(
'orm_default' => array(
'metadata_cache' => 'zend.static.local',
'query_cache' => 'zend.static.local',
),
),
),
请注意,Doctrine 会自动添加“doctrine.cache”前缀,这很烦人。到您配置的缓存服务的名称,因此当我们将“metadata_cache”配置为“zend.static.local”时,实际的缓存服务必须命名为“doctrine.cache.zend.static.local”。显然,您可以随意调用它们,但是您需要将该前缀添加到您所称呼的任何名称中。
关于caching - ZF2 Doctrine2 实体缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16664327/