【问题标题】:Doctrine2 with ZF2 Annotations caching?带有 ZF2 注释缓存的 Doctrine2?
【发布时间】:2012-11-07 11:36:03
【问题描述】:

我将 Doctrine2 与 ZF2 (Zend Framework2) 一起使用。 根据http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/
我在 Doctrine 中使用注释,我需要知道注释是否默认被缓存,如果缓存在哪里,如果不是,我如何缓存它们。

我知道 Symfony2/Doctrine2 会缓存注释数据,我如何使用 Zend2 来做呢?

【问题讨论】:

    标签: caching doctrine-orm annotations zend-framework2


    【解决方案1】:

    使用 memcache 进行注释缓存的示例是 (module.config.php):

    'service_manager' => array(
    
        'factories' => array(
            'doctrine.cache.my_memcache' => function(\Zend\ServiceManager\ServiceManager $sm) {
                $cache = new \Doctrine\Common\Cache\MemcacheCache();
                $memcache = new \Memcache();
                $memcache->connect('localhost', 11211);
                $cache->setMemcache($memcache);
    
                return $cache;
            }
        )
    

    这将为教义创建基本的内存缓存对象。之后,您必须告诉教义将此缓存用于这样的注释(同样,module.config.php):

    'doctrine' => array(
        'driver' => array(
            __NAMESPACE__ . '_driver' => array(
                'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                'cache' => 'my_memcache', // <- this points to the doctrine.cache.my_memcache factory we created above
                'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
            ),
            'orm_default' => array(
                'drivers' => array(
                    __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
                ),
            ),
        ),
    ),
    

    或者,您可以使用学说的数组缓存。只需将 'cache' => 'my_memcache' 更改为 'cache' => 'array' (据我所知,这应该是默认值。 希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-25
      • 2013-07-17
      • 2019-03-09
      • 1970-01-01
      • 2012-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多