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
|
* Can be enabled or disabled through site configuration
|
||||||
* Also sets a default time if no time is passed to it to enforce caching
|
* 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) {
|
public function __construct($config, $debug) {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->debug = $debug;
|
$this->debug = $debug;
|
||||||
if (! $config['memcache']['enabled'] ) $this->debug->append("Not storing any values in memcache");
|
if (! $config['memcache']['enabled'] ) {
|
||||||
return parent::__construct();
|
$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))
|
if (empty($expiration))
|
||||||
$expiration = $this->config['memcache']['expiration'] + rand( -$this->config['memcache']['splay'], $this->config['memcache']['splay']);
|
$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);
|
$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) {
|
public function get($key, $cache_cb = NULL, &$cas_token = NULL) {
|
||||||
if (! $this->config['memcache']['enabled']) return false;
|
if (! $this->config['memcache']['enabled']) return false;
|
||||||
$this->debug->append("Trying to fetch key " . $this->config['memcache']['keyprefix'] . "$key from cache", 3);
|
$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);
|
$this->debug->append("Found key in cache", 3);
|
||||||
return $data;
|
return $data;
|
||||||
} else {
|
} else {
|
||||||
@ -56,6 +61,14 @@ class StatsCache extends Memcached {
|
|||||||
return $data;
|
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);
|
$memcache = new StatsCache($config, $debug);
|
||||||
|
|||||||
@ -315,10 +315,12 @@ $config['confirmations'] = 120;
|
|||||||
/**
|
/**
|
||||||
* Memcache configuration
|
* Memcache configuration
|
||||||
*
|
*
|
||||||
* Even though you can disable the memcache for debugging purposes, the memcache
|
* To disable memcache set option $config['memcache']['enabled'] = false
|
||||||
* library is still required for mmcfe-ng to work. You should not disable this in
|
* After disable memcache installation of memcache is not required.
|
||||||
* a live environment since a lot of data is cached for the website to increase load
|
*
|
||||||
* times!
|
* 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
|
* Explanations
|
||||||
* enabled : Disable (false) memcache for debugging or enable (true) it
|
* enabled : Disable (false) memcache for debugging or enable (true) it
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user