Merge pull request #441 from ilya-stromberg/issue-409-switch-off-memcached-via-comfig
(#409) Do not use Memcached if it switched off via config
This commit is contained in:
commit
aa05a9e0b0
@ -9,12 +9,17 @@ if (!defined('SECURITY'))
|
||||
* Can be enabled or disabled through site configuration
|
||||
* Also sets a default time if no time is passed to it to enforce caching
|
||||
**/
|
||||
class StatsCache extends Memcached {
|
||||
class StatsCache {
|
||||
private $cache;
|
||||
|
||||
public function __construct($config, $debug) {
|
||||
$this->config = $config;
|
||||
$this->debug = $debug;
|
||||
if (! $config['memcache']['enabled'] ) $this->debug->append("Not storing any values in memcache");
|
||||
return parent::__construct();
|
||||
if (! $config['memcache']['enabled'] ) {
|
||||
$this->debug->append("Not storing any values in memcache");
|
||||
} else {
|
||||
$this->cache = new Memcached();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -26,7 +31,7 @@ class StatsCache extends Memcached {
|
||||
if (empty($expiration))
|
||||
$expiration = $this->config['memcache']['expiration'] + rand( -$this->config['memcache']['splay'], $this->config['memcache']['splay']);
|
||||
$this->debug->append("Storing " . $this->config['memcache']['keyprefix'] . "$key with expiration $expiration", 3);
|
||||
return parent::set($this->config['memcache']['keyprefix'] . $key, $value, $expiration);
|
||||
return $this->cache->set($this->config['memcache']['keyprefix'] . $key, $value, $expiration);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,7 +41,7 @@ class StatsCache extends Memcached {
|
||||
public function get($key, $cache_cb = NULL, &$cas_token = NULL) {
|
||||
if (! $this->config['memcache']['enabled']) return false;
|
||||
$this->debug->append("Trying to fetch key " . $this->config['memcache']['keyprefix'] . "$key from cache", 3);
|
||||
if ($data = parent::get($this->config['memcache']['keyprefix'].$key)) {
|
||||
if ($data = $this->cache->get($this->config['memcache']['keyprefix'].$key)) {
|
||||
$this->debug->append("Found key in cache", 3);
|
||||
return $data;
|
||||
} else {
|
||||
@ -55,7 +60,15 @@ class StatsCache extends Memcached {
|
||||
if ($this->config['memcache']['enabled']) $this->set($key, $data, $expiration);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is invoked if the called method was not realised in this class
|
||||
**/
|
||||
public function __call($name, $arguments) {
|
||||
if (! $this->config['memcache']['enabled']) return false;
|
||||
//Invoke method $name of $this->cache class with array of $arguments
|
||||
return call_user_func_array(array($this->cache, $name), $arguments);
|
||||
}
|
||||
}
|
||||
|
||||
$memcache = new StatsCache($config, $debug);
|
||||
|
||||
@ -315,10 +315,12 @@ $config['confirmations'] = 120;
|
||||
/**
|
||||
* Memcache configuration
|
||||
*
|
||||
* Even though you can disable the memcache for debugging purposes, the memcache
|
||||
* library is still required for mmcfe-ng to work. You should not disable this in
|
||||
* a live environment since a lot of data is cached for the website to increase load
|
||||
* times!
|
||||
* To disable memcache set option $config['memcache']['enabled'] = false
|
||||
* After disable memcache installation of memcache is not required.
|
||||
*
|
||||
* Please note that a memcache is greatly increasing performance
|
||||
* when combined with the `statistics.php` cronjob. Disabling this
|
||||
* is not recommended in a live environment!
|
||||
*
|
||||
* Explanations
|
||||
* enabled : Disable (false) memcache for debugging or enable (true) it
|
||||
|
||||
Loading…
Reference in New Issue
Block a user