MDL-25290 cache: Fixed things up per coding style
This commit is contained in:
Vendored
+14
-10
@@ -48,11 +48,11 @@ $notifysuccess = true;
|
||||
|
||||
if (!empty($action) && confirm_sesskey()) {
|
||||
switch ($action) {
|
||||
case 'rescandefinitions' :
|
||||
case 'rescandefinitions' : // Rescan definitions.
|
||||
cache_config_writer::update_definitions();
|
||||
redirect($PAGE->url);
|
||||
break;
|
||||
case 'addstore' :
|
||||
case 'addstore' : // Add the requested store.
|
||||
$plugin = required_param('plugin', PARAM_PLUGIN);
|
||||
$mform = cache_administration_helper::get_add_store_form($plugin);
|
||||
$title = get_string('addstore', 'cache', $plugins[$plugin]['name']);
|
||||
@@ -71,7 +71,7 @@ if (!empty($action) && confirm_sesskey()) {
|
||||
redirect($PAGE->url, get_string('addstoresuccess', 'cache', $plugins[$plugin]['name']), 5);
|
||||
}
|
||||
break;
|
||||
case 'editstore' :
|
||||
case 'editstore' : // Edit the requested store.
|
||||
$plugin = required_param('plugin', PARAM_PLUGIN);
|
||||
$store = required_param('store', PARAM_TEXT);
|
||||
$mform = cache_administration_helper::get_edit_store_form($plugin, $store);
|
||||
@@ -91,7 +91,7 @@ if (!empty($action) && confirm_sesskey()) {
|
||||
redirect($PAGE->url, get_string('editstoresuccess', 'cache', $plugins[$plugin]['name']), 5);
|
||||
}
|
||||
break;
|
||||
case 'deletestore' :
|
||||
case 'deletestore' : // Delete a given store.
|
||||
$store = required_param('store', PARAM_TEXT);
|
||||
$confirm = optional_param('confirm', false, PARAM_BOOL);
|
||||
|
||||
@@ -106,14 +106,16 @@ if (!empty($action) && confirm_sesskey()) {
|
||||
if ($notifysuccess) {
|
||||
if (!$confirm) {
|
||||
$title = get_string('confirmstoredeletion', 'cache');
|
||||
$url = new moodle_url($PAGE->url, array('store' => $store, 'confirm' => 1, 'action' => $action, 'sesskey' => sesskey()));
|
||||
$params = array('store' => $store, 'confirm' => 1, 'action' => $action, 'sesskey' => sesskey());
|
||||
$url = new moodle_url($PAGE->url, $params);
|
||||
$button = new single_button($url, get_string('deletestore', 'cache'));
|
||||
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_heading($SITE->fullname);
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($title);
|
||||
echo $OUTPUT->confirm(get_string('deletestoreconfirmation', 'cache', $stores[$store]['name']), $button, $PAGE->url);
|
||||
$confirmation = get_string('deletestoreconfirmation', 'cache', $stores[$store]['name']);
|
||||
echo $OUTPUT->confirm($confirmation, $button, $PAGE->url);
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
} else {
|
||||
@@ -123,7 +125,7 @@ if (!empty($action) && confirm_sesskey()) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'editdefinitionmapping' :
|
||||
case 'editdefinitionmapping' : // Edit definition mappings.
|
||||
$definition = required_param('definition', PARAM_TEXT);
|
||||
$title = get_string('editdefinitionmappings', 'cache', $definition);
|
||||
$mform = new cache_definition_mappings_form($PAGE->url, array('definition' => $definition));
|
||||
@@ -141,7 +143,7 @@ if (!empty($action) && confirm_sesskey()) {
|
||||
redirect($PAGE->url);
|
||||
}
|
||||
break;
|
||||
case 'editmodemappings': // Edit default mode mappings
|
||||
case 'editmodemappings': // Edit default mode mappings.
|
||||
$mform = new cache_mode_mappings_form(null, $stores);
|
||||
$mform->set_data(array(
|
||||
'mode_'.cache_store::MODE_APPLICATION => key($defaultmodestores[cache_store::MODE_APPLICATION]),
|
||||
@@ -162,8 +164,10 @@ if (!empty($action) && confirm_sesskey()) {
|
||||
}
|
||||
break;
|
||||
|
||||
case 'purge': // Purge a store cache
|
||||
// TODO
|
||||
case 'purge': // Purge a store cache.
|
||||
$store = required_param('store', PARAM_TEXT);
|
||||
cache_helper::purge_store($store);
|
||||
redirect($PAGE->url, get_string('purgestoresuccess', 'cache'), 5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+21
-20
@@ -75,7 +75,7 @@ class cache_config {
|
||||
* Please use cache_config::instance to get an instance of the cache config that is ready to be used.
|
||||
*/
|
||||
public function __construct() {
|
||||
//$this->config_load();
|
||||
// Nothing to do here but look pretty.
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +94,7 @@ class cache_config {
|
||||
* @return bool True if it exists
|
||||
*/
|
||||
public static function config_file_exists() {
|
||||
// Allow for late static binding
|
||||
// Allow for late static binding.
|
||||
return file_exists(self::get_config_file_path());
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ class cache_config {
|
||||
$this->configdefinitionmappings = array();
|
||||
$this->configlockmappings = array();
|
||||
|
||||
// Filter the lock instances
|
||||
// Filter the lock instances.
|
||||
$defaultlock = null;
|
||||
foreach ($configuration['locks'] as $conf) {
|
||||
if (!is_array($conf)) {
|
||||
@@ -144,7 +144,7 @@ class cache_config {
|
||||
continue;
|
||||
}
|
||||
if (!array_key_exists('name', $conf)) {
|
||||
// Not a valid definition configuration
|
||||
// Not a valid definition configuration.
|
||||
continue;
|
||||
}
|
||||
$name = $conf['name'];
|
||||
@@ -159,17 +159,18 @@ class cache_config {
|
||||
$this->configlocks[$name] = $conf;
|
||||
}
|
||||
|
||||
// Filter the stores
|
||||
// Filter the stores.
|
||||
$availableplugins = cache_helper::early_get_cache_plugins();
|
||||
foreach ($configuration['stores'] as $store) {
|
||||
if (!is_array($store) || !array_key_exists('name', $store) || !array_key_exists('plugin', $store)) {
|
||||
// Not a valid instance configuration
|
||||
// Not a valid instance configuration.
|
||||
debugging('Invalid cache store in config. Missing name or plugin.', DEBUG_DEVELOPER);
|
||||
continue;
|
||||
}
|
||||
$plugin = $store['plugin'];
|
||||
$class = 'cachestore_'.$plugin;
|
||||
if (!array_key_exists($plugin, $availableplugins) && (!class_exists($class) || !is_subclass_of($class, 'cache_store'))) {
|
||||
$exists = array_key_exists($plugin, $availableplugins);
|
||||
if (!$exists && (!class_exists($class) || !is_subclass_of($class, 'cache_store'))) {
|
||||
// Not a valid plugin, or has been uninstalled, just skip it an carry on.
|
||||
debugging('Invalid cache store in config. Not an available plugin.', DEBUG_DEVELOPER);
|
||||
continue;
|
||||
@@ -196,14 +197,14 @@ class cache_config {
|
||||
$this->configstores[$store['name']] = $store;
|
||||
}
|
||||
|
||||
// Filter the definitions
|
||||
// Filter the definitions.
|
||||
foreach ($configuration['definitions'] as $id => $conf) {
|
||||
if (!is_array($conf)) {
|
||||
// Something is very wrong here.
|
||||
continue;
|
||||
}
|
||||
if (!array_key_exists('mode', $conf) || !array_key_exists('component', $conf) || !array_key_exists('area', $conf)) {
|
||||
// Not a valid definition configuration
|
||||
// Not a valid definition configuration.
|
||||
continue;
|
||||
}
|
||||
if (array_key_exists($id, $this->configdefinitions)) {
|
||||
@@ -212,27 +213,27 @@ class cache_config {
|
||||
}
|
||||
$conf['mode'] = (int)$conf['mode'];
|
||||
if ($conf['mode'] < cache_store::MODE_APPLICATION || $conf['mode'] > cache_store::MODE_REQUEST) {
|
||||
// Invalid cache mode used for the definition
|
||||
// Invalid cache mode used for the definition.
|
||||
continue;
|
||||
}
|
||||
$this->configdefinitions[$id] = $conf;
|
||||
}
|
||||
|
||||
// Filter the mode mappings
|
||||
// Filter the mode mappings.
|
||||
foreach ($configuration['modemappings'] as $mapping) {
|
||||
if (!is_array($mapping) || !array_key_exists('mode', $mapping) || !array_key_exists('store', $mapping)) {
|
||||
// Not a valid mapping configuration
|
||||
// Not a valid mapping configuration.
|
||||
debugging('A cache mode mapping entry is invalid.', DEBUG_DEVELOPER);
|
||||
continue;
|
||||
}
|
||||
if (!array_key_exists($mapping['store'], $this->configstores)) {
|
||||
// Mapped array instance doesn't exist
|
||||
// Mapped array instance doesn't exist.
|
||||
debugging('A cache mode mapping exists for a mode or store that does not exist.', DEBUG_DEVELOPER);
|
||||
continue;
|
||||
}
|
||||
$mapping['mode'] = (int)$mapping['mode'];
|
||||
if ($mapping['mode'] < 0 || $mapping['mode'] > 4) {
|
||||
// Invalid cache type used for the mapping
|
||||
// Invalid cache type used for the mapping.
|
||||
continue;
|
||||
}
|
||||
if (!array_key_exists('sort', $mapping)) {
|
||||
@@ -241,18 +242,18 @@ class cache_config {
|
||||
$this->configmodemappings[] = $mapping;
|
||||
}
|
||||
|
||||
// Filter the definition mappings
|
||||
// Filter the definition mappings.
|
||||
foreach ($configuration['definitionmappings'] as $mapping) {
|
||||
if (!is_array($mapping) || !array_key_exists('definition', $mapping) || !array_key_exists('store', $mapping)) {
|
||||
// Not a valid mapping configuration
|
||||
// Not a valid mapping configuration.
|
||||
continue;
|
||||
}
|
||||
if (!array_key_exists($mapping['store'], $this->configstores)) {
|
||||
// Mapped array instance doesn't exist
|
||||
// Mapped array instance doesn't exist.
|
||||
continue;
|
||||
}
|
||||
if (!array_key_exists($mapping['definition'], $this->configdefinitions)) {
|
||||
// Mapped array instance doesn't exist
|
||||
// Mapped array instance doesn't exist.
|
||||
continue;
|
||||
}
|
||||
if (!array_key_exists('sort', $mapping)) {
|
||||
@@ -280,7 +281,7 @@ class cache_config {
|
||||
$cachefile = self::get_config_file_path();
|
||||
|
||||
if (!file_exists($cachefile)) {
|
||||
throw new cache_exception('Default cache configuration could not be found. It should have already been created by now.');
|
||||
throw new cache_exception('Default cache config could not be found. It should have already been created by now.');
|
||||
}
|
||||
include($cachefile);
|
||||
if (!is_array($configuration)) {
|
||||
@@ -318,7 +319,7 @@ class cache_config {
|
||||
if ($a['sort'] == $b['sort']) {
|
||||
return 0;
|
||||
}
|
||||
return ($a['sort'] < $b['sort']) ? 1 : -1 ;
|
||||
return ($a['sort'] < $b['sort']) ? 1 : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Vendored
+1
-1
@@ -278,7 +278,7 @@ class cache_definition {
|
||||
$component = (string)$definition['component'];
|
||||
$area = (string)$definition['area'];
|
||||
|
||||
// Set the defaults
|
||||
// Set the defaults.
|
||||
$requireidentifiers = array();
|
||||
$requiredataguarantee = false;
|
||||
$requiremultipleidentifiers = false;
|
||||
|
||||
Vendored
+2
-2
@@ -38,7 +38,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class cachestore_dummy implements cache_store {
|
||||
|
||||
|
||||
/**
|
||||
* The name of this store.
|
||||
* @var string
|
||||
@@ -51,7 +51,7 @@ class cachestore_dummy implements cache_store {
|
||||
* @var bool
|
||||
*/
|
||||
protected $persist = false;
|
||||
|
||||
|
||||
/**
|
||||
* The persistent store array
|
||||
* @var array
|
||||
|
||||
Vendored
+4
-3
@@ -209,7 +209,7 @@ class cache_factory {
|
||||
*/
|
||||
public function create_store_from_config($name, array $details, cache_definition $definition) {
|
||||
if (!array_key_exists($name, $this->stores)) {
|
||||
// name, plugin, configuration, class
|
||||
// Properties: name, plugin, configuration, class.
|
||||
$class = $details['class'];
|
||||
$store = new $class($details['name'], $details['configuration']);
|
||||
$this->stores[$name] = $store;
|
||||
@@ -241,7 +241,7 @@ class cache_factory {
|
||||
require_once($CFG->dirroot.'/cache/locallib.php');
|
||||
$class .= '_writer';
|
||||
}
|
||||
|
||||
|
||||
// Check if this is a PHPUnit test and redirect to the phpunit config classes if it is.
|
||||
if (defined('PHPUNIT_TEST') && PHPUNIT_TEST) {
|
||||
require_once($CFG->dirroot.'/cache/locallib.php');
|
||||
@@ -290,7 +290,8 @@ class cache_factory {
|
||||
if (!$definition) {
|
||||
throw new coding_exception('The requested cache definition does not exist.'. $id, $id);
|
||||
} else {
|
||||
debugging('Cache definitions reparsed causing cache reset in order to locate definition. You should bump the version number to ensure definitions are reprocessed.', DEBUG_DEVELOPER);
|
||||
debugging('Cache definitions reparsed causing cache reset in order to locate definition.
|
||||
You should bump the version number to ensure definitions are reprocessed.', DEBUG_DEVELOPER);
|
||||
}
|
||||
}
|
||||
$this->definitions[$id] = cache_definition::load($id, $definition, $aggregate);
|
||||
|
||||
Vendored
+28
-3
@@ -187,7 +187,7 @@ class cache_helper {
|
||||
}
|
||||
$pluginname = clean_param($pluginname, PARAM_PLUGIN);
|
||||
if (empty($pluginname)) {
|
||||
// better ignore plugins with problematic names here
|
||||
// Better ignore plugins with problematic names here.
|
||||
continue;
|
||||
}
|
||||
$result[$pluginname] = $fulldir.'/'.$pluginname;
|
||||
@@ -276,7 +276,7 @@ class cache_helper {
|
||||
* @return bool
|
||||
*/
|
||||
public static function purge_by_definition($component, $area, array $identifiers = array()) {
|
||||
// Create the cache
|
||||
// Create the cache.
|
||||
$cache = cache::make($component, $area, $identifiers);
|
||||
// Purge baby, purge.
|
||||
$cache->purge();
|
||||
@@ -303,7 +303,7 @@ class cache_helper {
|
||||
if ($invalidationeventset === false) {
|
||||
// Get the event invalidation cache.
|
||||
$cache = cache::make('core', 'eventinvalidation');
|
||||
// Create a key to invalidate all
|
||||
// Create a key to invalidate all.
|
||||
$data = array(
|
||||
'purged' => cache::now()
|
||||
);
|
||||
@@ -402,6 +402,31 @@ class cache_helper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purges a store given its name.
|
||||
*
|
||||
* @param string $storename
|
||||
* @return bool
|
||||
*/
|
||||
public static function purge_store($storename) {
|
||||
$config = cache_config::instance();
|
||||
foreach ($config->get_all_stores() as $store) {
|
||||
if ($store['name'] !== $storename) {
|
||||
continue;
|
||||
}
|
||||
$class = $store['class'];
|
||||
$instance = new $class($store['name'], $store['configuration']);
|
||||
if (!$instance->is_ready()) {
|
||||
continue;
|
||||
}
|
||||
$definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'core', 'cache_purge');
|
||||
$instance->initialise($definition);
|
||||
$instance->purge();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the translated name of the definition.
|
||||
*
|
||||
|
||||
Vendored
+23
-16
@@ -314,7 +314,7 @@ class cache implements cache_loader, cache_is_key_aware {
|
||||
} else if ($this->perfdebug) {
|
||||
cache_helper::record_cache_hit($this->storetype, $this->definition->get_id());
|
||||
}
|
||||
// 5. Validate strictness
|
||||
// 5. Validate strictness.
|
||||
if ($strictness === MUST_EXIST && $result === false) {
|
||||
throw new moodle_exception('Requested key did not exist in any cache stores and could not be loaded.');
|
||||
}
|
||||
@@ -350,7 +350,7 @@ class cache implements cache_loader, cache_is_key_aware {
|
||||
$resultstore = array();
|
||||
$keystofind = array();
|
||||
|
||||
// First up check the persist cache for each key
|
||||
// First up check the persist cache for each key.
|
||||
$isusingpersist = $this->is_using_persist_cache();
|
||||
foreach ($keys as $key) {
|
||||
$pkey = $this->parse_key($key);
|
||||
@@ -423,7 +423,7 @@ class cache implements cache_loader, cache_is_key_aware {
|
||||
}
|
||||
unset($result);
|
||||
|
||||
// Final step is to check strictness
|
||||
// Final step is to check strictness.
|
||||
if ($strictness === MUST_EXIST) {
|
||||
foreach ($keys as $key) {
|
||||
if (!array_key_exists($key, $fullresult)) {
|
||||
@@ -647,7 +647,7 @@ class cache implements cache_loader, cache_is_key_aware {
|
||||
$parsedkey = $this->parse_key($key);
|
||||
$this->delete_from_persist_cache($parsedkey);
|
||||
if ($recurse && !empty($this->loader)) {
|
||||
// Delete from the bottom of the stack first
|
||||
// Delete from the bottom of the stack first.
|
||||
$this->loader->delete($key, $recurse);
|
||||
}
|
||||
return $this->store->delete($parsedkey);
|
||||
@@ -669,7 +669,7 @@ class cache implements cache_loader, cache_is_key_aware {
|
||||
}
|
||||
}
|
||||
if ($recurse && !empty($this->loader)) {
|
||||
// Delete from the bottom of the stack first
|
||||
// Delete from the bottom of the stack first.
|
||||
$this->loader->delete_many($keys, $recurse);
|
||||
}
|
||||
return $this->store->delete_many($parsedkeys);
|
||||
@@ -681,11 +681,11 @@ class cache implements cache_loader, cache_is_key_aware {
|
||||
* @return bool True on success, false otherwise
|
||||
*/
|
||||
public function purge() {
|
||||
// 1. Purge the persist cache
|
||||
// 1. Purge the persist cache.
|
||||
$this->persistcache = array();
|
||||
// 2. Purge the store
|
||||
// 2. Purge the store.
|
||||
$this->store->purge();
|
||||
// 3. Optionally pruge any stacked loaders
|
||||
// 3. Optionally pruge any stacked loaders.
|
||||
if ($this->loader) {
|
||||
$this->loader->purge();
|
||||
}
|
||||
@@ -981,7 +981,7 @@ class cache_application extends cache implements cache_loader_with_locking {
|
||||
$todelete = array();
|
||||
// Iterate the returned data for the events.
|
||||
foreach ($events as $event => $keys) {
|
||||
// Look at each key and check the timestamp
|
||||
// Look at each key and check the timestamp.
|
||||
foreach ($keys as $key => $timestamp) {
|
||||
// If the timestamp of the event is more than or equal to the last invalidation (happened between the last
|
||||
// invalidation and now)then we need to invaliate the key.
|
||||
@@ -994,7 +994,7 @@ class cache_application extends cache implements cache_loader_with_locking {
|
||||
$todelete = array_unique($todelete);
|
||||
$this->delete_many($todelete);
|
||||
}
|
||||
// Set the time of the last invalidation
|
||||
// Set the time of the last invalidation.
|
||||
$this->set('lastinvalidation', cache::now());
|
||||
}
|
||||
}
|
||||
@@ -1008,7 +1008,12 @@ class cache_application extends cache implements cache_loader_with_locking {
|
||||
public function get_identifier() {
|
||||
static $instances = 0;
|
||||
if ($this->lockidentifier === null) {
|
||||
$this->lockidentifier = md5($this->get_definition()->generate_definition_hash().sesskey().$instances++.'cache_application');
|
||||
$this->lockidentifier = md5(
|
||||
$this->get_definition()->generate_definition_hash() .
|
||||
sesskey() .
|
||||
$instances++ .
|
||||
'cache_application'
|
||||
);
|
||||
}
|
||||
return $this->lockidentifier;
|
||||
}
|
||||
@@ -1017,7 +1022,7 @@ class cache_application extends cache implements cache_loader_with_locking {
|
||||
* Fixes the instance up after a clone.
|
||||
*/
|
||||
public function __clone() {
|
||||
// Force a new idenfitier
|
||||
// Force a new idenfitier.
|
||||
$this->lockidentifier = null;
|
||||
}
|
||||
|
||||
@@ -1314,10 +1319,10 @@ class cache_session extends cache {
|
||||
// Iterate the returned data for the events.
|
||||
foreach ($events as $event => $keys) {
|
||||
if ($keys === false) {
|
||||
// No data to be invalidated yet
|
||||
// No data to be invalidated yet.
|
||||
continue;
|
||||
}
|
||||
// Look at each key and check the timestamp
|
||||
// Look at each key and check the timestamp.
|
||||
foreach ($keys as $key => $timestamp) {
|
||||
// If the timestamp of the event is more than or equal to the last invalidation (happened between the last
|
||||
// invalidation and now)then we need to invaliate the key.
|
||||
@@ -1330,7 +1335,7 @@ class cache_session extends cache {
|
||||
$todelete = array_unique($todelete);
|
||||
$this->delete_many($todelete);
|
||||
}
|
||||
// Set the time of the last invalidation
|
||||
// Set the time of the last invalidation.
|
||||
$this->set('lastsessioninvalidation', cache::now());
|
||||
}
|
||||
}
|
||||
@@ -1352,4 +1357,6 @@ class cache_session extends cache {
|
||||
* @copyright 2012 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class cache_request extends cache {}
|
||||
class cache_request extends cache {
|
||||
// This comment appeases code pre-checker ;) !
|
||||
}
|
||||
Vendored
+7
-5
@@ -67,7 +67,8 @@ class cachestore_addinstance_form extends moodleform {
|
||||
$form->setType('lock', PARAM_TEXT);
|
||||
} else {
|
||||
$form->addElement('hidden', 'lock', '');
|
||||
$form->addElement('static', 'lock-value', get_string('lockmethod', 'cache'), '<em>'.get_string('nativelocking', 'cache').'</em>');
|
||||
$form->addElement('static', 'lock-value', get_string('lockmethod', 'cache'),
|
||||
'<em>'.get_string('nativelocking', 'cache').'</em>');
|
||||
}
|
||||
|
||||
if (method_exists($this, 'configuration_definition')) {
|
||||
@@ -125,7 +126,8 @@ class cache_definition_mappings_form extends moodleform {
|
||||
$form = $this->_form;
|
||||
|
||||
list($component, $area) = explode('/', $definition, 2);
|
||||
list($currentstores, $storeoptions, $defaults) = cache_administration_helper::get_definition_store_options($component, $area);
|
||||
list($currentstores, $storeoptions, $defaults) =
|
||||
cache_administration_helper::get_definition_store_options($component, $area);
|
||||
|
||||
$form->addElement('hidden', 'definition', $definition);
|
||||
$form->addElement('hidden', 'action', 'editdefinitionmapping');
|
||||
@@ -133,7 +135,6 @@ class cache_definition_mappings_form extends moodleform {
|
||||
$requiredoptions = max(3, count($currentstores)+1);
|
||||
$requiredoptions = min($requiredoptions, count($storeoptions));
|
||||
|
||||
|
||||
$options = array('' => get_string('none'));
|
||||
foreach ($storeoptions as $option => $def) {
|
||||
$options[$option] = $option;
|
||||
@@ -142,7 +143,7 @@ class cache_definition_mappings_form extends moodleform {
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0 ; $i < $requiredoptions; $i++) {
|
||||
for ($i = 0; $i < $requiredoptions; $i++) {
|
||||
$title = '...';
|
||||
if ($i === 0) {
|
||||
$title = get_string('mappingprimary', 'cache');
|
||||
@@ -158,7 +159,8 @@ class cache_definition_mappings_form extends moodleform {
|
||||
}
|
||||
|
||||
if (!empty($defaults)) {
|
||||
$form->addElement('static', 'defaults', get_string('defaultmappings', 'cache'), html_writer::tag('strong', join(', ', $defaults)));
|
||||
$form->addElement('static', 'defaults', get_string('defaultmappings', 'cache'),
|
||||
html_writer::tag('strong', join(', ', $defaults)));
|
||||
$form->addHelpButton('defaults', 'defaultmappings', 'cache');
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-1
@@ -143,7 +143,8 @@ class cache_exception extends moodle_exception {
|
||||
* @param mixed $a
|
||||
* @param mixed $debuginfo
|
||||
*/
|
||||
public function __construct($errorcode, $module = 'cache', $link = '', $a = NULL, $debuginfo = null) {
|
||||
public function __construct($errorcode, $module = 'cache', $link = '', $a = null, $debuginfo = null) {
|
||||
// This may appear like a useless override but you will notice that we have set a MUCH more useful default for $module.
|
||||
parent::__construct($errorcode, $module, $link, $a, $debuginfo);
|
||||
}
|
||||
}
|
||||
Vendored
+6
-9
@@ -115,7 +115,7 @@ class cache_config_writer extends cache_config {
|
||||
if (!class_exists($class)) {
|
||||
$plugins = get_plugin_list_with_file('cachestore', 'lib.php');
|
||||
if (!array_key_exists($plugin, $plugins)) {
|
||||
throw new cache_exception('Invalid plugin name specified. The plugin either does not exist or is not a valid cache plugin.');
|
||||
throw new cache_exception('Invalid plugin name specified. The plugin does not exist or is not valid.');
|
||||
}
|
||||
$file = $plugins[$plugin];
|
||||
if (file_exists($file)) {
|
||||
@@ -297,7 +297,6 @@ class cache_config_writer extends cache_config {
|
||||
'features' => cachestore_file::get_supported_features(),
|
||||
'modes' => cache_store::MODE_APPLICATION,
|
||||
'default' => true,
|
||||
//'class' => 'cachestore_file'
|
||||
),
|
||||
'default_session' => array(
|
||||
'name' => 'default_session',
|
||||
@@ -306,7 +305,6 @@ class cache_config_writer extends cache_config {
|
||||
'features' => cachestore_session::get_supported_features(),
|
||||
'modes' => cache_store::MODE_SESSION,
|
||||
'default' => true,
|
||||
//'class' => 'cachestore_session'
|
||||
),
|
||||
'default_request' => array(
|
||||
'name' => 'default_request',
|
||||
@@ -315,7 +313,6 @@ class cache_config_writer extends cache_config {
|
||||
'features' => cachestore_static::get_supported_features(),
|
||||
'modes' => cache_store::MODE_REQUEST,
|
||||
'default' => true,
|
||||
//'class' => 'cachestore_static'
|
||||
)
|
||||
);
|
||||
$writer->configdefinitions = self::locate_definitions();
|
||||
@@ -353,7 +350,7 @@ class cache_config_writer extends cache_config {
|
||||
* Calls config_save further down, you should redirect immediately or asap after calling this method.
|
||||
*/
|
||||
public static function update_definitions() {
|
||||
$config = cache_config_writer::instance();
|
||||
$config = self::instance();
|
||||
$config->write_definitions_to_cache(self::locate_definitions());
|
||||
}
|
||||
|
||||
@@ -374,7 +371,7 @@ class cache_config_writer extends cache_config {
|
||||
foreach ($plugintypes as $type => $location) {
|
||||
$plugins = get_plugin_list_with_file($type, 'db/caches.php');
|
||||
foreach ($plugins as $plugin => $filepath) {
|
||||
$component = clean_param($type.'_'.$plugin, PARAM_COMPONENT); // standardised plugin name
|
||||
$component = clean_param($type.'_'.$plugin, PARAM_COMPONENT); // Standardised plugin name.
|
||||
$files[$component] = $filepath;
|
||||
}
|
||||
}
|
||||
@@ -422,7 +419,7 @@ class cache_config_writer extends cache_config {
|
||||
return array();
|
||||
}
|
||||
$definitions = array();
|
||||
include $file;
|
||||
include($file);
|
||||
return $definitions;
|
||||
}
|
||||
|
||||
@@ -715,7 +712,7 @@ abstract class cache_administration_helper extends cache_helper {
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public static function get_add_store_form($plugin) {
|
||||
global $CFG; // Needed for includes
|
||||
global $CFG; // Needed for includes.
|
||||
$plugindir = get_plugin_directory('cachestore', $plugin);
|
||||
$class = 'cachestore_addinstance_form';
|
||||
if (file_exists($plugindir.'/addinstanceform.php')) {
|
||||
@@ -766,7 +763,7 @@ abstract class cache_administration_helper extends cache_helper {
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public static function get_edit_store_form($plugin, $store) {
|
||||
global $CFG; // Needed for includes
|
||||
global $CFG; // Needed for includes.
|
||||
$plugindir = get_plugin_directory('cachestore', $plugin);
|
||||
$class = 'cachestore_addinstance_form';
|
||||
if (file_exists($plugindir.'/addinstanceform.php')) {
|
||||
|
||||
Vendored
+2
-2
@@ -150,9 +150,9 @@ class cachelock_file implements cache_lock_interface {
|
||||
$iterations = 0;
|
||||
$maxiterations = $this->blockattempts;
|
||||
while (($result = $this->lock($key, false)) === false) {
|
||||
// usleep causes the application to cleep to x microseconds.
|
||||
// Usleep causes the application to cleep to x microseconds.
|
||||
// Before anyone asks there are 1'000'000 microseconds to a second.
|
||||
usleep(rand(1000, 50000)); // Sleep between 1 and 50 milliseconds
|
||||
usleep(rand(1000, 50000)); // Sleep between 1 and 50 milliseconds.
|
||||
$iterations++;
|
||||
if ($iterations > $maxiterations) {
|
||||
// BOOM! We've exceeded the maximum number of iterations we want to block for.
|
||||
|
||||
Vendored
+16
-7
@@ -214,21 +214,27 @@ class core_cache_renderer extends plugin_renderer_base {
|
||||
'mappings',
|
||||
'actions'
|
||||
);
|
||||
$table->data = array();
|
||||
$table->data = array('none', 'cache');
|
||||
|
||||
$none = new lang_string('none', 'cache');
|
||||
foreach ($definitions as $id => $definition) {
|
||||
$htmlactions = array();
|
||||
foreach ($actions as $action) {
|
||||
$action['url']->param('definition', $id);
|
||||
$htmlactions[] = $this->output->action_link($action['url'], $action['text']);
|
||||
}
|
||||
if (!empty($definition['mappings'])) {
|
||||
$mapping = join(', ', $definition['mappings']);
|
||||
} else {
|
||||
$mapping = '<em>'.$none.'</em>';
|
||||
}
|
||||
|
||||
$row = new html_table_row(array(
|
||||
$definition['name'],
|
||||
get_string('mode_'.$definition['mode'], 'cache'),
|
||||
$definition['component'],
|
||||
$definition['area'],
|
||||
(!empty($definition['mappings'])) ? join(', ', $definition['mappings']) : '<em>'.get_string('none', 'cache').'</em>',
|
||||
$mapping,
|
||||
join(', ', $htmlactions)
|
||||
));
|
||||
$row->attributes['class'] = 'definition-'.$definition['component'].'-'.$definition['area'];
|
||||
@@ -239,7 +245,9 @@ class core_cache_renderer extends plugin_renderer_base {
|
||||
$html .= $this->output->heading(get_string('definitionsummaries', 'cache'), 3);
|
||||
$html .= html_writer::table($table);
|
||||
|
||||
$html .= html_writer::tag('div', html_writer::link(new moodle_url('/cache/admin.php', array('action' => 'rescandefinitions', 'sesskey' => sesskey())), get_string('rescandefinitions', 'cache')), array('id' => 'core-cache-rescan-definitions'));
|
||||
$url = new moodle_url('/cache/admin.php', array('action' => 'rescandefinitions', 'sesskey' => sesskey()));
|
||||
$link = html_writer::link($url, get_string('rescandefinitions', 'cache'));
|
||||
$html .= html_writer::tag('div', $link, array('id' => 'core-cache-rescan-definitions'));
|
||||
|
||||
$html .= html_writer::end_tag('div');
|
||||
return $html;
|
||||
@@ -278,7 +286,8 @@ class core_cache_renderer extends plugin_renderer_base {
|
||||
$html = html_writer::start_tag('div', array('id' => 'core-cache-mode-mappings'));
|
||||
$html .= $this->output->heading(get_string('defaultmappings', 'cache'), 3);
|
||||
$html .= html_writer::table($table);
|
||||
$html .= html_writer::tag('div', html_writer::link($editurl, get_string('editmappings', 'cache')), array('class' => 'edit-link'));
|
||||
$link = html_writer::link($editurl, get_string('editmappings', 'cache'));
|
||||
$html .= html_writer::tag('div', $link, array('class' => 'edit-link'));
|
||||
$html .= html_writer::end_tag('div');
|
||||
return $html;
|
||||
}
|
||||
@@ -297,19 +306,19 @@ class core_cache_renderer extends plugin_renderer_base {
|
||||
'name',
|
||||
'default',
|
||||
'uses',
|
||||
// 'actions'
|
||||
// Useful later: 'actions'.
|
||||
);
|
||||
$table->rowclasses = array(
|
||||
'lock_name',
|
||||
'lock_default',
|
||||
'lock_uses',
|
||||
// 'lock_actions',
|
||||
// Useful later: 'lock_actions',.
|
||||
);
|
||||
$table->head = array(
|
||||
get_string('lockname', 'cache'),
|
||||
get_string('lockdefault', 'cache'),
|
||||
get_string('lockuses', 'cache'),
|
||||
// get_string('actions', 'cache')
|
||||
// Useful later: get_string('actions', 'cache').
|
||||
);
|
||||
$table->data = array();
|
||||
$tick = $this->output->pix_icon('i/tick_green_big', '');
|
||||
|
||||
Vendored
+9
-9
@@ -259,7 +259,7 @@ class cachestore_file implements cache_store, cache_is_key_aware {
|
||||
if (!$readfile) {
|
||||
return false;
|
||||
}
|
||||
// Check the filesize first, likely not needed but important none the less
|
||||
// Check the filesize first, likely not needed but important none the less.
|
||||
$filesize = filesize($file);
|
||||
if (!$filesize) {
|
||||
return false;
|
||||
@@ -269,14 +269,14 @@ class cachestore_file implements cache_store, cache_is_key_aware {
|
||||
return false;
|
||||
}
|
||||
// Lock it up!
|
||||
// We don't care if this succeeds or not, on some systems it will, on some it won't, meah either way
|
||||
// We don't care if this succeeds or not, on some systems it will, on some it won't, meah either way.
|
||||
flock($handle, LOCK_SH);
|
||||
// HACK ALERT
|
||||
// There is a problem when reading from the file during PHPUNIT tests. For one reason or another the filesize is not correct
|
||||
// Doesn't happen during normal operation, just during unit tests.
|
||||
// Read it
|
||||
// Read it.
|
||||
$data = fread($handle, $filesize+128);
|
||||
// Unlock it
|
||||
// Unlock it.
|
||||
flock($handle, LOCK_UN);
|
||||
// Return it unserialised.
|
||||
return $this->prep_data_after_read($data);
|
||||
@@ -298,7 +298,7 @@ class cachestore_file implements cache_store, cache_is_key_aware {
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deletes an item from the cache store.
|
||||
*
|
||||
@@ -345,11 +345,11 @@ class cachestore_file implements cache_store, cache_is_key_aware {
|
||||
// Couldn't write the file.
|
||||
return false;
|
||||
}
|
||||
// Record the key if required
|
||||
// Record the key if required.
|
||||
if ($this->prescan) {
|
||||
$this->keys[$filename] = cache::now() + 1;
|
||||
}
|
||||
// Return true.. it all worked **miracles**
|
||||
// Return true.. it all worked **miracles**.
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -441,7 +441,7 @@ class cachestore_file implements cache_store, cache_is_key_aware {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Purges the cache deleting all items within it.
|
||||
*
|
||||
@@ -465,7 +465,7 @@ class cachestore_file implements cache_store, cache_is_key_aware {
|
||||
protected function ensure_path_exists() {
|
||||
if (!is_writable($this->path)) {
|
||||
if ($this->custompath && !$this->autocreate) {
|
||||
throw new coding_exception('File store path does not exist. You must create it and make it writable to the web server.');
|
||||
throw new coding_exception('File store path does not exist. It must exist and be writable by the web server.');
|
||||
}
|
||||
if (!make_writable_directory($this->path, false)) {
|
||||
throw new coding_exception('File store path does not exist and can not be created.');
|
||||
|
||||
Vendored
+3
-3
@@ -27,6 +27,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$plugin->version = 2012091000; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2012090700; // Requires this Moodle version
|
||||
$plugin->component = 'cachestore_file'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->version = 2012091000; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2012090700; // Requires this Moodle version.
|
||||
$plugin->component = 'cachestore_file'; // Full name of the plugin.
|
||||
Vendored
+5
-1
@@ -26,4 +26,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$settings->add(new admin_setting_configtextarea('cachestore_memcache/testservers', new lang_string('testservers', 'cachestore_memcache'), new lang_string('testservers_desc', 'cachestore_memcache'), '', PARAM_RAW, 60, 3));
|
||||
$settings->add(new admin_setting_configtextarea(
|
||||
'cachestore_memcache/testservers',
|
||||
new lang_string('testservers', 'cachestore_memcache'),
|
||||
new lang_string('testservers_desc', 'cachestore_memcache'),
|
||||
'', PARAM_RAW, 60, 3));
|
||||
Vendored
+3
-3
@@ -26,6 +26,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$plugin->version = 2012091000; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2012090700; // Requires this Moodle version
|
||||
$plugin->component = 'cachestore_memcache'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->version = 2012091000; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2012090700; // Requires this Moodle version.
|
||||
$plugin->component = 'cachestore_memcache'; // Full name of the plugin.
|
||||
+4
-3
@@ -53,7 +53,8 @@ class cachestore_memcached_addinstance_form extends cachestore_addinstance_form
|
||||
$form->setDefault('compression', 1);
|
||||
$form->setType('compression', PARAM_BOOL);
|
||||
|
||||
$form->addElement('select', 'serialiser', get_string('useserialiser', 'cachestore_memcached'), cachestore_memcached::config_get_serialiser_options());
|
||||
$serialiseroptions = cachestore_memcached::config_get_serialiser_options();
|
||||
$form->addElement('select', 'serialiser', get_string('useserialiser', 'cachestore_memcached'), $serialiseroptions);
|
||||
$form->addHelpButton('serialiser', 'useserialiser', 'cachestore_memcached');
|
||||
$form->setDefault('serialiser', Memcached::SERIALIZER_PHP);
|
||||
$form->setType('serialiser', PARAM_NUMBER);
|
||||
@@ -62,12 +63,12 @@ class cachestore_memcached_addinstance_form extends cachestore_addinstance_form
|
||||
$form->setType('prefix', PARAM_ALPHANUM);
|
||||
$form->addHelpButton('prefix', 'prefix', 'cachestore_memcached');
|
||||
|
||||
$form->addElement('select', 'hash', get_string('hash', 'cachestore_memcached'), cachestore_memcached::config_get_hash_options());
|
||||
$hashoptions = cachestore_memcached::config_get_hash_options();
|
||||
$form->addElement('select', 'hash', get_string('hash', 'cachestore_memcached'), $hashoptions);
|
||||
$form->addHelpButton('hash', 'hash', 'cachestore_memcached');
|
||||
$form->setDefault('serialiser', Memcached::HASH_DEFAULT);
|
||||
$form->setType('serialiser', PARAM_INT);
|
||||
|
||||
|
||||
$form->addElement('selectyesno', 'bufferwrites', get_string('bufferwrites', 'cachestore_memcached'));
|
||||
$form->addHelpButton('bufferwrites', 'bufferwrites', 'cachestore_memcached');
|
||||
$form->setDefault('bufferwrites', 0);
|
||||
|
||||
Vendored
+6
-2
@@ -74,7 +74,7 @@ class cachestore_memcached implements cache_store {
|
||||
* @var bool
|
||||
*/
|
||||
protected $isready = false;
|
||||
|
||||
|
||||
/**
|
||||
* The cache definition this store was initialised with.
|
||||
* @var cache_definition
|
||||
@@ -98,7 +98,11 @@ class cachestore_memcached implements cache_store {
|
||||
}
|
||||
|
||||
$compression = array_key_exists('compression', $configuration) ? (bool)$configuration['compression'] : true;
|
||||
$serialiser = (array_key_exists('serialiser', $configuration)) ? (int)$configuration['serialiser'] : Memcached::SERIALIZER_PHP;
|
||||
if (array_key_exists('serialiser', $configuration)) {
|
||||
$serialiser = (int)$configuration['serialiser'];
|
||||
} else {
|
||||
$serialiser = Memcached::SERIALIZER_PHP;
|
||||
}
|
||||
$prefix = (!empty($configuration['prefix'])) ? (string)$configuration['prefix'] : crc32($name);
|
||||
$hashmethod = (array_key_exists('hash', $configuration)) ? (int)$configuration['hash'] : Memcached::HASH_DEFAULT;
|
||||
$bufferwrites = array_key_exists('bufferwrites', $configuration) ? (bool)$configuration['bufferwrites'] : false;
|
||||
|
||||
Vendored
+5
-1
@@ -26,4 +26,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$settings->add(new admin_setting_configtextarea('cachestore_memcached/testservers', new lang_string('testservers', 'cachestore_memcached'), new lang_string('testservers_desc', 'cachestore_memcached'), '', PARAM_RAW, 60, 3));
|
||||
$settings->add(new admin_setting_configtextarea(
|
||||
'cachestore_memcached/testservers',
|
||||
new lang_string('testservers', 'cachestore_memcached'),
|
||||
new lang_string('testservers_desc', 'cachestore_memcached'),
|
||||
'', PARAM_RAW, 60, 3));
|
||||
Vendored
+2
-2
@@ -27,5 +27,5 @@
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$plugin->version = 2012091000; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2012090700; // Requires this Moodle version
|
||||
$plugin->component = 'cachestore_memcached'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->requires = 2012090700; // Requires this Moodle version.
|
||||
$plugin->component = 'cachestore_memcached'; // Full name of the plugin.
|
||||
+1
-3
@@ -33,9 +33,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Include the necessary evils.
|
||||
*/
|
||||
// Include the necessary evils.
|
||||
require_once($CFG->dirroot.'/cache/forms.php');
|
||||
require_once($CFG->dirroot.'/cache/stores/mongodb/lib.php');
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -252,7 +252,7 @@ class cachestore_mongodb implements cache_store {
|
||||
if (!is_array($key)) {
|
||||
$key = array('key' => $key);
|
||||
}
|
||||
|
||||
|
||||
$result = $this->collection->findOne($key);
|
||||
if ($result === null || !array_key_exists('data', $result)) {
|
||||
return false;
|
||||
|
||||
Vendored
+5
-1
@@ -26,4 +26,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$settings->add(new admin_setting_configtextarea('cachestore_mongodb/testserver', new lang_string('testserver', 'cachestore_mongodb'), new lang_string('testserver_desc', 'cachestore_mongodb'), '', PARAM_RAW, 60, 3));
|
||||
$settings->add(new admin_setting_configtextarea(
|
||||
'cachestore_mongodb/testserver',
|
||||
new lang_string('testserver', 'cachestore_mongodb'),
|
||||
new lang_string('testserver_desc', 'cachestore_mongodb'),
|
||||
'', PARAM_RAW, 60, 3));
|
||||
Vendored
+2
-2
@@ -25,5 +25,5 @@
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$plugin->version = 2012091000; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2012090700; // Requires this Moodle version
|
||||
$plugin->component = 'cachestore_mongodb'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->requires = 2012090700; // Requires this Moodle version.
|
||||
$plugin->component = 'cachestore_mongodb'; // Full name of the plugin.
|
||||
Vendored
+1
-1
@@ -385,7 +385,7 @@ abstract class session_data_store {
|
||||
* @var array
|
||||
*/
|
||||
private static $sessionstore = null;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a static store by reference... REFERENCE SUPER IMPORTANT.
|
||||
*
|
||||
|
||||
Vendored
+3
-3
@@ -27,6 +27,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$plugin->version = 2012091000; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2012090700; // Requires this Moodle version
|
||||
$plugin->component = 'cachestore_session'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->version = 2012091000; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2012090700; // Requires this Moodle version.
|
||||
$plugin->component = 'cachestore_session'; // Full name of the plugin.
|
||||
Vendored
+1
-1
@@ -379,7 +379,7 @@ class cachestore_static extends static_data_store implements cache_store, cache_
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class static_data_store {
|
||||
|
||||
|
||||
/**
|
||||
* An array for storage.
|
||||
* @var array
|
||||
|
||||
Vendored
+2
-2
@@ -28,5 +28,5 @@
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$plugin->version = 2012091000; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2012090700; // Requires this Moodle version
|
||||
$plugin->component = 'cachestore_static'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->requires = 2012090700; // Requires this Moodle version.
|
||||
$plugin->component = 'cachestore_static'; // Full name of the plugin.
|
||||
Vendored
+32
-37
@@ -28,9 +28,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Include the necessary evils.
|
||||
*/
|
||||
// Include the necessary evils.
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot.'/cache/locallib.php');
|
||||
require_once($CFG->dirroot.'/cache/tests/fixtures/lib.php');
|
||||
@@ -64,13 +62,13 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
$stores = $instance->get_all_stores();
|
||||
$this->assertCount(4, $stores);
|
||||
foreach ($stores as $name => $store) {
|
||||
// Check its an array
|
||||
// Check its an array.
|
||||
$this->assertInternalType('array', $store);
|
||||
// Check the name is the key
|
||||
// Check the name is the key.
|
||||
$this->assertEquals($name, $store['name']);
|
||||
// Check that it has been declared default
|
||||
// Check that it has been declared default.
|
||||
$this->assertTrue($store['default']);
|
||||
// Required attributes = name + plugin + configuration + modes + features
|
||||
// Required attributes = name + plugin + configuration + modes + features.
|
||||
$this->assertArrayHasKey('name', $store);
|
||||
$this->assertArrayHasKey('plugin', $store);
|
||||
$this->assertArrayHasKey('configuration', $store);
|
||||
@@ -86,12 +84,12 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
cache_store::MODE_REQUEST => false,
|
||||
);
|
||||
foreach ($modemappings as $mapping) {
|
||||
// We expect 3 properties
|
||||
// We expect 3 properties.
|
||||
$this->assertCount(3, $mapping);
|
||||
// Required attributes = mode + store
|
||||
// Required attributes = mode + store.
|
||||
$this->assertArrayHasKey('mode', $mapping);
|
||||
$this->assertArrayHasKey('store', $mapping);
|
||||
// Record the mode
|
||||
// Record the mode.
|
||||
$modes[$mapping['mode']] = true;
|
||||
}
|
||||
|
||||
@@ -106,13 +104,11 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
$this->assertArrayHasKey('core/eventinvalidation', $definitions);
|
||||
|
||||
$definitionmappings = $instance->get_definition_mappings();
|
||||
$found = false;
|
||||
foreach ($definitionmappings as $mapping) {
|
||||
// Required attributes = definition + store
|
||||
// Required attributes = definition + store.
|
||||
$this->assertArrayHasKey('definition', $mapping);
|
||||
$this->assertArrayHasKey('store', $mapping);
|
||||
}
|
||||
$this->assertTrue($found, 'The expected mapping for default locking definition to the default locking store was not found.');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,7 +178,7 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
|
||||
$this->assertTrue($cache->purge());
|
||||
|
||||
// Check all read methods
|
||||
// Check all read methods.
|
||||
$this->assertFalse($cache->get($key));
|
||||
$this->assertFalse($cache->has($key));
|
||||
$result = $cache->get_many(array($key));
|
||||
@@ -191,12 +187,12 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
$this->assertFalse($cache->has_any(array($key)));
|
||||
$this->assertFalse($cache->has_all(array($key)));
|
||||
|
||||
// Set the data
|
||||
// Set the data.
|
||||
$this->assertTrue($cache->set($key, $datascalar));
|
||||
// Setting it more than once should be permitted
|
||||
// Setting it more than once should be permitted.
|
||||
$this->assertTrue($cache->set($key, $datascalar));
|
||||
|
||||
// Recheck the read methods
|
||||
// Recheck the read methods.
|
||||
$this->assertEquals($datascalar, $cache->get($key));
|
||||
$this->assertTrue($cache->has($key));
|
||||
$result = $cache->get_many(array($key));
|
||||
@@ -205,18 +201,18 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
$this->assertTrue($cache->has_any(array($key)));
|
||||
$this->assertTrue($cache->has_all(array($key)));
|
||||
|
||||
// Delete it
|
||||
// Delete it.
|
||||
$this->assertTrue($cache->delete($key));
|
||||
|
||||
// Check its gone
|
||||
// Check its gone.
|
||||
$this->assertFalse($cache->get($key));
|
||||
$this->assertFalse($cache->has($key));
|
||||
|
||||
// Test arrays
|
||||
// Test arrays.
|
||||
$this->assertTrue($cache->set($key, $dataarray));
|
||||
$this->assertEquals($dataarray, $cache->get($key));
|
||||
|
||||
// Test objects
|
||||
// Test objects.
|
||||
$this->assertTrue($cache->set($key, $dataobject));
|
||||
$this->assertEquals($dataobject, $cache->get($key));
|
||||
|
||||
@@ -227,14 +223,14 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
$this->assertEquals('red_ptc_wfc', $result->property1);
|
||||
$this->assertEquals('blue_ptc_wfc', $result->property2);
|
||||
|
||||
// Test set many
|
||||
// Test set many.
|
||||
$cache->set_many(array('key1' => 'data1', 'key2' => 'data2'));
|
||||
$this->assertEquals('data1', $cache->get('key1'));
|
||||
$this->assertEquals('data2', $cache->get('key2'));
|
||||
$this->assertTrue($cache->delete('key1'));
|
||||
$this->assertTrue($cache->delete('key2'));
|
||||
|
||||
// Test delete many
|
||||
// Test delete many.
|
||||
$this->assertTrue($cache->set('key1', 'data1'));
|
||||
$this->assertTrue($cache->set('key2', 'data2'));
|
||||
|
||||
@@ -262,15 +258,15 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
$cache = cache::make('phpunit', 'datasourcetest');
|
||||
$this->assertInstanceOf('cache_application', $cache);
|
||||
|
||||
// Purge it to be sure
|
||||
// Purge it to be sure.
|
||||
$this->assertTrue($cache->purge());
|
||||
// It won't be there yet
|
||||
// It won't be there yet.
|
||||
$this->assertFalse($cache->has('Test'));
|
||||
|
||||
// It should load it ;)
|
||||
// It should load it ;).
|
||||
$this->assertTrue($cache->has('Test', true));
|
||||
|
||||
// Purge it to be sure
|
||||
// Purge it to be sure.
|
||||
$this->assertTrue($cache->purge());
|
||||
$this->assertEquals('Test has no value really.', $cache->get('Test'));
|
||||
}
|
||||
@@ -289,13 +285,13 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
$cache = cache::make('phpunit', 'overridetest');
|
||||
$this->assertInstanceOf('cache_phpunit_dummy_overrideclass', $cache);
|
||||
$this->assertInstanceOf('cache_application', $cache);
|
||||
// Purge it to be sure
|
||||
// Purge it to be sure.
|
||||
$this->assertTrue($cache->purge());
|
||||
// It won't be there yet
|
||||
// It won't be there yet.
|
||||
$this->assertFalse($cache->has('Test'));
|
||||
// Add it
|
||||
// Add it.
|
||||
$this->assertTrue($cache->set('Test', 'Test has no value really.'));
|
||||
// Check its there
|
||||
// Check its there.
|
||||
$this->assertEquals('Test has no value really.', $cache->get('Test'));
|
||||
}
|
||||
|
||||
@@ -348,7 +344,7 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
$this->assertTrue($cache->set('testkey2', 'test data 2'));
|
||||
$this->assertEquals('test data 2', $cache->get('testkey2'));
|
||||
|
||||
// Test invalidating a single entry
|
||||
// Test invalidating a single entry.
|
||||
cache_helper::invalidate_by_event('crazyevent', array('testkey1'));
|
||||
|
||||
$this->assertFalse($cache->get('testkey1'));
|
||||
@@ -356,7 +352,7 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
|
||||
$this->assertTrue($cache->set('testkey1', 'test data 1'));
|
||||
|
||||
// Test invalidating both entries
|
||||
// Test invalidating both entries.
|
||||
cache_helper::invalidate_by_event('crazyevent', array('testkey1', 'testkey2'));
|
||||
|
||||
$this->assertFalse($cache->get('testkey1'));
|
||||
@@ -380,7 +376,7 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
$this->assertEquals('test data 2', $cache->get('testkey2'));
|
||||
|
||||
cache_helper::invalidate_by_definition('phpunit', 'definitioninvalidation', array(), 'testkey1');
|
||||
|
||||
|
||||
$this->assertFalse($cache->get('testkey1'));
|
||||
$this->assertEquals('test data 2', $cache->get('testkey2'));
|
||||
|
||||
@@ -408,7 +404,6 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
// We need to add data the to cache, invalidate it by event, manually force it back without MUC knowing to simulate a
|
||||
// disconnected/distributed setup (think load balanced server using local cache), instantiate the cache again and finally
|
||||
// check that it is not picked up.
|
||||
|
||||
$instance = cache_config_phpunittest::instance();
|
||||
$instance->phpunit_add_definition('phpunit/eventinvalidationtest', array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
@@ -429,7 +424,7 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
// OK data added, data invalidated, and invalidation time has been set.
|
||||
// Now we need to manually add back the data and adjust the invalidation time.
|
||||
$timefile = $CFG->dataroot.'/cache/cachestore_file/default_application/phpunit_eventinvalidationtest/494515064.cache';
|
||||
$timecont = serialize(cache::now() - 60); // Back 60sec in the past to force it to re-invalidate
|
||||
$timecont = serialize(cache::now() - 60); // Back 60sec in the past to force it to re-invalidate.
|
||||
file_put_contents($timefile, $timecont);
|
||||
$this->assertTrue(file_exists($timefile));
|
||||
|
||||
@@ -449,7 +444,7 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
$cache = cache::make('phpunit', 'eventinvalidationtest');
|
||||
$this->assertEquals('test data 1', $cache->get('testkey1'));
|
||||
|
||||
// Test 2: Rebuild and test the invalidation of the event via the invalidation cache
|
||||
// Test 2: Rebuild and test the invalidation of the event via the invalidation cache.
|
||||
cache_factory::reset();
|
||||
$instance = cache_config_phpunittest::instance();
|
||||
$instance->phpunit_add_definition('phpunit/eventinvalidationtest', array(
|
||||
|
||||
Vendored
+3
-1
@@ -143,4 +143,6 @@ class cache_phpunit_dummy_datasource implements cache_data_source {
|
||||
* @copyright 2012 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class cache_phpunit_dummy_overrideclass extends cache_application {}
|
||||
class cache_phpunit_dummy_overrideclass extends cache_application {
|
||||
// Satisfying the code pre-checker is just part of my day job.
|
||||
}
|
||||
@@ -1,4 +1,30 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Cache language strings
|
||||
*
|
||||
* This file is part of Moodle's cache API, affectionately called MUC.
|
||||
* It contains the components that are requried in order to use caching.
|
||||
*
|
||||
* @package core
|
||||
* @category cache
|
||||
* @copyright 2012 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['actions'] = 'Actions';
|
||||
$string['addinstance'] = 'Add instance';
|
||||
@@ -61,6 +87,7 @@ $string['none'] = 'None';
|
||||
$string['plugin'] = 'Plugin';
|
||||
$string['pluginsummaries'] = 'Plugin summaries';
|
||||
$string['purge'] = 'Purge';
|
||||
$string['purgestoresuccess'] = 'Successfully purged the requested store.';
|
||||
$string['requestcount'] = 'Test with {$a} requests';
|
||||
$string['rescandefinitions'] = 'Rescan definitions';
|
||||
$string['result'] = 'Result';
|
||||
|
||||
+4
-1
@@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
$definitions = array(
|
||||
// Used to store processed lang files.
|
||||
'string' => array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'component' => 'core',
|
||||
@@ -34,6 +35,7 @@ $definitions = array(
|
||||
'persistent' => true,
|
||||
'persistentmaxsize' => 3
|
||||
),
|
||||
// Used to store database meta information.
|
||||
'databasemeta' => array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'requireidentifiers' => array(
|
||||
@@ -42,11 +44,12 @@ $definitions = array(
|
||||
'persistent' => true,
|
||||
'persistentmaxsize' => 2
|
||||
),
|
||||
// Used to store data from the config + config_plugins table in the database.
|
||||
'config' => array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'persistent' => true
|
||||
),
|
||||
// Event invalidation cache
|
||||
// Event invalidation cache.
|
||||
'eventinvalidation' => array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'persistent' => true,
|
||||
|
||||
Reference in New Issue
Block a user