Browse files

MDL-39448 MUC: Memcache configurable key names

  • Loading branch information...
1 parent 06340a1 commit 1df3b0ae2441d46d58169635af14881d4b65008a @sammarshallou sammarshallou committed with danpoltawski May 1, 2013
View
6 cache/stores/memcache/addinstanceform.php
@@ -46,5 +46,11 @@ protected function configuration_definition() {
$form->addHelpButton('servers', 'servers', 'cachestore_memcache');
$form->addRule('servers', get_string('required'), 'required');
$form->setType('servers', PARAM_RAW);
+
+ $form->addElement('text', 'prefix', get_string('prefix', 'cachestore_memcache'),
+ array('maxlength' => 5, 'size' => 5));
+ $form->addHelpButton('prefix', 'prefix', 'cachestore_memcache');
+ $form->setType('prefix', PARAM_ALPHAEXT);
+ $form->setDefault('prefix', 'mdl_');
}
}
View
4 cache/stores/memcache/lang/en/cachestore_memcache.php
@@ -27,6 +27,10 @@
defined('MOODLE_INTERNAL') || die();
$string['pluginname'] = 'Memcache';
+$string['prefix'] = 'Key prefix';
+$string['prefix_help'] = 'This prefix is used for all key names on the memcache server.
+* If you only have one Moodle instance using this server, you can leave this value default.
+* Due to key length restrictions, a maximum of 5 characters is permitted.';
$string['servers'] = 'Servers';
$string['servers_help'] = 'This sets the servers that should be utilised by this memcache adapter.
Servers should be defined one per line and consist of a server address and optionally a port and weight.
View
26 cache/stores/memcache/lib.php
@@ -52,6 +52,12 @@ class cachestore_memcache extends cache_store implements cache_is_configurable {
protected $connection;
/**
+ * Key prefix for this memcache.
+ * @var string
+ */
+ protected $prefix;
+
+ /**
* An array of servers to use in the connection args.
* @var array
*/
@@ -82,6 +88,12 @@ class cachestore_memcache extends cache_store implements cache_is_configurable {
protected $definition;
/**
+ * Default prefix for key names.
+ * @var string
+ */
+ const DEFAULT_PREFIX = 'mdl_';
+
+ /**
* Constructs the store instance.
*
* Noting that this function is not an initialisation. It is used to prepare the store for use.
@@ -111,6 +123,11 @@ public function __construct($name, array $configuration = array()) {
}
$this->servers[] = $server;
}
+ if (empty($configuration['prefix'])) {
+ $this->prefix = self::DEFAULT_PREFIX;
+ } else {
+ $this->prefix = $configuration['prefix'];
+ }
$this->connection = new Memcache;
foreach ($this->servers as $server) {
@@ -212,7 +229,7 @@ protected function parse_key($key) {
if (strlen($key) > 245) {
$key = '_sha1_'.sha1($key);
}
- $key = 'mdl_'.$key;
+ $key = $this->prefix . $key;
return $key;
}
@@ -338,6 +355,7 @@ public static function config_get_configuration_array($data) {
}
return array(
'servers' => $servers,
+ 'prefix' => $data->prefix,
);
}
@@ -356,6 +374,12 @@ public static function config_set_edit_form_data(moodleform $editform, array $co
}
$data['servers'] = join("\n", $servers);
}
+ if (!empty($config['prefix'])) {
+ $data['prefix'] = $config['prefix'];
+ } else {
+ $data['prefix'] = self::DEFAULT_PREFIX;
+ }
+
$editform->set_data($data);
}
View
4 cache/stores/memcache/version.php
@@ -26,6 +26,6 @@
defined('MOODLE_INTERNAL') || die;
-$plugin->version = 2012112900; // The current module version (Date: YYYYMMDDXX)
+$plugin->version = 2012112901; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2012112900; // Requires this Moodle version.
-$plugin->component = 'cachestore_memcache'; // Full name of the plugin.
+$plugin->component = 'cachestore_memcache'; // Full name of the plugin.

0 comments on commit 1df3b0a

Please sign in to comment.