From 4e381e8ea5d7c88f2963681e8ac5aa7503de6a69 Mon Sep 17 00:00:00 2001 From: Thomas Metois Date: Mon, 7 Nov 2016 12:00:40 +0100 Subject: [PATCH] Doctrine add cache prod env --- config/autoload/global.php | 50 +++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/config/autoload/global.php b/config/autoload/global.php index d205663..4ec899c 100644 --- a/config/autoload/global.php +++ b/config/autoload/global.php @@ -12,6 +12,44 @@ */ return array( // DOCTRINE CONF + 'service_manager' => array( + 'factories' => array( + 'doctrine.cache.mycache' => function(\Zend\ServiceManager\ServiceManager $sm){ + $arrayCache = new \Doctrine\Common\Cache\ArrayCache(); + + if(getenv('APPLICATION_ENV') == 'production'){ + if(extension_loaded('apc')){ + $apcCache = new \Doctrine\Common\Cache\ApcCache(); + $chainCache = new \Doctrine\Common\Cache\ChainCache([$apcCache,$arrayCache]); + return $chainCache; + }elseif(extension_loaded('apcu')){ + $apcuCache = new \Doctrine\Common\Cache\ApcuCache(); + $chainCache = new \Doctrine\Common\Cache\ChainCache([$apcuCache,$arrayCache]); + return $chainCache; + } + // TODO: untested / add param for memchache(d) host & port + /*elseif(extension_loaded('memcache')){ + $memcache = new \Memcache(); + if($memcache->connect('localhost', 11211)){ + $cache = new \Doctrine\Common\Cache\MemcacheCache(); + $cache->setMemcache($mem); + $chainCache = new \Doctrine\Common\Cache\ChainCache([$cache,$arrayCache]); + return $chainCache; + } + }elseif(extension_loaded('memcached')){ + $memcache = new \Memcached(); + if($memcache->connect('localhost', 11211)){ + $cache = new \Doctrine\Common\Cache\MemcachedCache(); + $cache->setMemcached($mem); + $chainCache = new \Doctrine\Common\Cache\ChainCache([$cache,$arrayCache]); + return $chainCache; + } + }*/ + } + return $arrayCache; + }, + ), + ), 'doctrine' => array( 'connection' => array( 'orm_default' => array( @@ -71,9 +109,9 @@ return array( ), 'configuration' => array( 'orm_default' => array( - 'metadata_cache' => 'array', - 'query_cache' => 'array', - 'result_cache' => 'array', + 'metadata_cache' => 'mycache', + 'query_cache' => 'mycache', + 'result_cache' => 'mycache', 'driver' => 'orm_default', // This driver will be defined later 'generate_proxies' => true, 'proxy_dir' => 'data/DoctrineORMModule/Proxy', @@ -85,9 +123,9 @@ return array( 'second_level_cache' => array(), ), 'orm_cli' => array( - 'metadata_cache' => 'array', - 'query_cache' => 'array', - 'result_cache' => 'array', + 'metadata_cache' => 'mycache', + 'query_cache' => 'mycache', + 'result_cache' => 'mycache', 'driver' => 'orm_cli', // This driver will be defined later 'generate_proxies' => true, 'proxy_dir' => 'data/DoctrineORMModule/Proxy',