1

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

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

4

1 回答 1

2

使用 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' (据我所知,这应该是默认值。希望对您有所帮助!

于 2013-05-30T20:38:52.707 回答