2012-11-07 54 views

回答

2

一個例子使用內存緩存用於註釋緩存將是(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'(根據我的情況,這應該是默認設置) 希望對您有所幫助!

+0

如何清除緩存? –