From 15e89ad4d3cb7a800f11d692d476003b7896e6bb Mon Sep 17 00:00:00 2001 From: Ilya Stromberg Date: Thu, 11 Jul 2013 19:11:03 +0400 Subject: [PATCH 1/3] (#409) Do not use Memcached if it switched off via config --- public/include/classes/statscache.class.php | 24 +++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/public/include/classes/statscache.class.php b/public/include/classes/statscache.class.php index e84386da..c3e9ea38 100644 --- a/public/include/classes/statscache.class.php +++ b/public/include/classes/statscache.class.php @@ -9,12 +9,16 @@ 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 +30,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 +40,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 +59,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); From 8f4b4ed9701611c027eb71aeca6f2a7cd74abe05 Mon Sep 17 00:00:00 2001 From: Ilya Stromberg Date: Thu, 11 Jul 2013 19:35:23 +0400 Subject: [PATCH 2/3] Fix code style --- public/include/classes/statscache.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/include/classes/statscache.class.php b/public/include/classes/statscache.class.php index c3e9ea38..e64d5d02 100644 --- a/public/include/classes/statscache.class.php +++ b/public/include/classes/statscache.class.php @@ -17,8 +17,9 @@ class StatsCache { $this->debug = $debug; if (! $config['memcache']['enabled'] ) { $this->debug->append("Not storing any values in memcache"); + } else { + $this->cache = new Memcached(); } - else { $this->cache = new Memcached(); } } /** From 521bcc80220ce68db186ecfc4acdf641c45477aa Mon Sep 17 00:00:00 2001 From: Ilya Stromberg Date: Thu, 11 Jul 2013 20:19:35 +0400 Subject: [PATCH 3/3] Fix built-in documentation --- public/include/config/global.inc.dist.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index 1cf894bf..b564d6a9 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -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