diff --git a/core/GlobalController.php b/core/GlobalController.php index 65e68b141..fa83de9a1 100644 --- a/core/GlobalController.php +++ b/core/GlobalController.php @@ -116,36 +116,41 @@ public function preDispatch() parent::preDispatch(); if(!$this->isDebug()) { - $frontendOptions = array( - 'lifetime' => 86400, - 'automatic_serialization' => true - ); - - $backendOptions = array( - 'cache_dir' => UtilityComponent::getCacheDirectory().'/db' - ); - - $cache = Zend_Cache::factory('Core', - 'File', - $frontendOptions, - $backendOptions); - - // Passing the object to cache by default - Zend_Db_Table_Abstract::setDefaultMetadataCache($cache); + $frontendOptions = array('automatic_serialization' => true, 'lifetime' => 86400); + if(extension_loaded('memcache')) + { + $cache = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, array()); + } + else if(extension_loaded('memcached')) + { + $cache = Zend_Cache::factory('Core', 'Libmemcached', $frontendOptions, array()); + } + else + { + $cacheDir = UtilityComponent::getCacheDirectory() . '/db'; + if(is_writable($cacheDir)) + { + $backendOptions = array('cache_dir' => $cacheDir); + $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions); + } + } + if(isset($cache)) + { + Zend_Db_Table_Abstract::setDefaultMetadataCache($cache); + } } } /** * Post-dispatch routines * - * Common usages for postDispatch() include rendering content in a sitewide + * Common usages for postDispatch() include rendering content in a site wide * template, link url correction, setting headers, etc. * * @return void */ public function postDispatch() { - parent::postDispatch(); if($this->isDebug() && $this->getEnvironment() != 'testing') {