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