php - How to use the cache in doctrine 2 and zend framework 2? -
php - How to use the cache in doctrine 2 and zend framework 2? -
plz need help here , i've goolged lot without result :/ how can exploit query , result stored in memcache , i'm working zend framework 2 , doctrine 2 ? , here configuration in module.config.php :
// doctrine config 'doctrine' => array( 'driver' => array( __namespace__ . '_driver' => array( 'class' => 'doctrine\orm\mapping\driver\annotationdriver', 'paths' => array(__dir__ . '/../src/' . __namespace__ . '/entity') ), 'orm_default' => array( 'drivers' => array( __namespace__ . '\entity' => __namespace__ . '_driver' ), ) ), /***** enabling memcache ****/ 'configuration' => array( 'orm_default' => array( 'metadata_cache' => 'mycache', 'query_cache' => 'mycache', 'result_cache' => 'mycache', ) /**** end ****/ ) ), 'service_manager' => array( 'factories' => array( 'translator' => 'zend\i18n\translator\translatorservicefactory', 'navigation' => 'zend\navigation\service\defaultnavigationfactory', 'doctrine.cache.mycache' => function ($sm) { $cache = new \doctrine\common\cache\memcachecache(); $memcache = new \memcache(); $memcache->connect('localhost', 11211); $cache->setmemcache($memcache); homecoming $cache; }, ), ),
any thought or link appeciated , thanks. regards.
i suppose using doctrinemodule, right? alter configuration this:
class="lang-php prettyprint-override">// doctrine config 'doctrine' => array( 'driver' => array( __namespace__ . '_driver' => array( 'class' => 'doctrine\orm\mapping\driver\annotationdriver', 'paths' => array(__dir__ . '/../src/' . __namespace__ . '/entity') ), 'orm_default' => array( 'drivers' => array( __namespace__ . '\entity' => __namespace__ . '_driver' ), ), ), /***** enabling memcache ****/ 'configuration' => array( 'orm_default' => array( 'metadata_cache' => 'memcache', 'query_cache' => 'memcache', 'result_cache' => 'memcache', ) ), /**** end ****/ 'cache' => array( 'memcache' => array( 'instance' => 'doctrine.cache.mycache', ), ), ), 'service_manager' => array( 'factories' => array( 'doctrine.cache.mycache' => function ($sm) { $cache = new \doctrine\common\cache\memcachecache(); $memcache = new \memcache(); $memcache->connect('localhost', 11211); $cache->setmemcache($memcache); homecoming $cache; }, ), ),
how work?
in module configuration predefined configurations every supported cache adapter, including memcache. configuration, saying "use memcache caching":
class="lang-php prettyprint-override">'configuration' => array( 'orm_default' => array( 'metadata_cache' => 'memcache', 'query_cache' => 'memcache', 'result_cache' => 'memcache', ) ),
this cache needs configured memcache instance , config saying "memcache instance available in servicemanager key 'doctrine.cache.mycache'"
class="lang-php prettyprint-override">'cache' => array( 'memcache' => array( 'instance' => 'doctrine.cache.mycache', ), ),
update:
how utilize result cache (documentation):
class="lang-php prettyprint-override">$cache = $entitymanager->getconfiguration()->getresultcacheimpl(); $cacheitemkey = 'my-item'; // test if item exists in cache if ($cache->contains($cacheitemkey)) { $item = $cache->fetch($cacheitemkey); // retrieve item cache } else { $item = $repository->find($id); // retrieve item repository $cache->save($cacheitemkey, $item); // save item cache }
php caching orm doctrine2 zend-framework2
Comments
Post a Comment