Merge branch 'MDL-39448-master' of git://github.com/sammarshallou/moodle

Conflicts:
	cache/stores/memcache/version.php
This commit is contained in:
Dan Poltawski 2013-05-07 11:43:23 +01:00
commit ac15fc95fa
4 changed files with 37 additions and 3 deletions

View File

@ -46,5 +46,11 @@ class cachestore_memcache_addinstance_form extends cachestore_addinstance_form {
$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 File

@ -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 File

@ -51,6 +51,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
@ -81,6 +87,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.
*
@ -111,6 +123,11 @@ class cachestore_memcache extends cache_store implements cache_is_configurable {
}
$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 @@ class cachestore_memcache extends cache_store implements cache_is_configurable {
if (strlen($key) > 245) {
$key = '_sha1_'.sha1($key);
}
$key = 'mdl_'.$key;
$key = $this->prefix . $key;
return $key;
}
@ -338,6 +355,7 @@ class cachestore_memcache extends cache_store implements cache_is_configurable {
}
return array(
'servers' => $servers,
'prefix' => $data->prefix,
);
}
@ -356,6 +374,12 @@ class cachestore_memcache extends cache_store implements cache_is_configurable {
}
$data['servers'] = join("\n", $servers);
}
if (!empty($config['prefix'])) {
$data['prefix'] = $config['prefix'];
} else {
$data['prefix'] = self::DEFAULT_PREFIX;
}
$editform->set_data($data);
}

View File

@ -26,6 +26,6 @@
defined('MOODLE_INTERNAL') || die;
$plugin->version = 2013050100; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2013050700; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2013050100; // Requires this Moodle version.
$plugin->component = 'cachestore_memcache'; // Full name of the plugin.
$plugin->component = 'cachestore_memcache'; // Full name of the plugin.