php - Enable Doctrine 2 cache in a ZF2 project -



php - Enable Doctrine 2 cache in a ZF2 project -

how enable cache in project working zend framework 2 , doctrine 2? , cache should enabled doctrine cache or zend cache?

here i've tried can't see diference in time execution added in

module\application\config\module.config.php

'doctrine.cache.my_memcache' => function ($sm) { $cache = new \doctrine\common\cache\memcachecache(); $memcache = new \memcache(); $memcache->connect('localhost', 11211); $cache->setmemcache($memcache); homecoming $cache; }, 'doctrine.cache.apc' => function ($sm){ $apc = new \doctrine\common\cache\apccache(); homecoming $apc; }, // doctrine config 'doctrine' => array( 'driver' => array( __namespace__ . '_driver' => array( 'class' => 'doctrine\orm\mapping\driver\annotationdriver', 'cache' => 'array', 'paths' => array(__dir__ . '/../src/' . __namespace__ . '/entity'), ), 'orm_default' => array( 'drivers' => array( __namespace__ . '\entity' => __namespace__ . '_driver' ), ) ), 'configuration' => array( 'orm_defaults' => array( 'metadata_cache' => 'apc', 'query_cache' => 'apc', 'result_cache' => 'my_memcache', ) ) ),

any help or thought or explication appreciated. thanks.

to cut down unnecessary headaches, utilize array cache on development time , memcached, redis or apc when application running on production environment.

you should set mill definitions under service_manager > factories key, not straight in module configuration array.

try this:

// module.config.php homecoming array( 'doctrine' => array( 'configuration' => array( 'orm_default' => array( 'metadata_cache' => 'mycache', 'query_cache' => 'mycache', 'result_cache' => 'mycache', 'hydration_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; }, ), ), );

also recommend moving factories individual mill classes, always. way, you'll have more readable, maintainable , efficient application on production environment help of merged configuration cache.

for example:

'service_manager' => array( 'factories' => array( 'doctrine.cache.mycache' => 'your\memcache\factory' // implement factoryinterface ), ), );

php caching zend-framework doctrine2 zend-framework2

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -