Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 5fc1d3c

Browse files
author
Jamie Snape
committed
Enable use of memcache
1 parent cfae682 commit 5fc1d3c

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

core/GlobalController.php

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,36 +116,41 @@ public function preDispatch()
116116
parent::preDispatch();
117117
if(!$this->isDebug())
118118
{
119-
$frontendOptions = array(
120-
'lifetime' => 86400,
121-
'automatic_serialization' => true
122-
);
123-
124-
$backendOptions = array(
125-
'cache_dir' => UtilityComponent::getCacheDirectory().'/db'
126-
);
127-
128-
$cache = Zend_Cache::factory('Core',
129-
'File',
130-
$frontendOptions,
131-
$backendOptions);
132-
133-
// Passing the object to cache by default
134-
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
119+
$frontendOptions = array('automatic_serialization' => true, 'lifetime' => 86400);
120+
if(extension_loaded('memcache'))
121+
{
122+
$cache = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, array());
123+
}
124+
else if(extension_loaded('memcached'))
125+
{
126+
$cache = Zend_Cache::factory('Core', 'Libmemcached', $frontendOptions, array());
127+
}
128+
else
129+
{
130+
$cacheDir = UtilityComponent::getCacheDirectory() . '/db';
131+
if(is_writable($cacheDir))
132+
{
133+
$backendOptions = array('cache_dir' => $cacheDir);
134+
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
135+
}
136+
}
137+
if(isset($cache))
138+
{
139+
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
140+
}
135141
}
136142
}
137143

138144
/**
139145
* Post-dispatch routines
140146
*
141-
* Common usages for postDispatch() include rendering content in a sitewide
147+
* Common usages for postDispatch() include rendering content in a site wide
142148
* template, link url correction, setting headers, etc.
143149
*
144150
* @return void
145151
*/
146152
public function postDispatch()
147153
{
148-
149154
parent::postDispatch();
150155
if($this->isDebug() && $this->getEnvironment() != 'testing')
151156
{

0 commit comments

Comments
 (0)