caching - ZF2 Doctrine2 实体缓存

标签 caching doctrine-orm zend-framework2

有人知道如何在zf2项目中缓存doctrine2实体吗?我找不到对此进行解释的教程或网站。我找不到任何开始定义实体文件缓存的信息。

你们中的一些人获得了工作链接或示例。

谢谢

最佳答案

你有两个选择

  1. 使用原则的 native 缓存,例如使用memcache (在内存缓存 block 中,您可以使用任何类型的学说支持的缓存,完整列表 cache drivers 可用)。
  2. 使用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/

相关文章:

javascript - 存储使用异步 Ajax 获取数据的 Javascript 函数

zend-framework - 如何在 ZF2 中禁用布局和 View 渲染器?

php - ZF2 中的跨数据库

php - APC 的 ZF2 PHP5.5 缓存存储替代品

sql-server-2005 - Sql 子查询\函数的性能

internet-explorer - 在 Internet Explorer 中第二次调用后 jQuery ajax 不工作

javascript - 如何用JavaScript清除网站的缓存?

php - Doctrine 的多对多自引用和互惠

symfony - 使用连接表更新学说

symfony - 在 Symfony2 中注册 Doctrine2 实体监听器作为服务