MDL-37683 cache: improved indentifier collection and storage
This commit is contained in:
Vendored
+11
-17
@@ -274,12 +274,6 @@ class cache_definition {
|
||||
*/
|
||||
protected $definitionhash = null;
|
||||
|
||||
/**
|
||||
* An identifier to make cache keys predictably unique.
|
||||
* @var string
|
||||
*/
|
||||
protected $cacheidentifier = '0';
|
||||
|
||||
/**
|
||||
* Creates a cache definition given a definition from the cache configuration or from a caches.php file.
|
||||
*
|
||||
@@ -680,15 +674,6 @@ class cache_definition {
|
||||
$this->keyprefixmulti = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an identifier for the cache.
|
||||
* This can be used
|
||||
* @param string $identifier
|
||||
*/
|
||||
public function set_cache_identifier($identifier) {
|
||||
$this->cacheidentifier = (string)$identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the requirements of this definition as a binary flag.
|
||||
* @return int
|
||||
@@ -739,7 +724,7 @@ class cache_definition {
|
||||
public function generate_single_key_prefix() {
|
||||
if ($this->keyprefixsingle === null) {
|
||||
$this->keyprefixsingle = $this->mode.'/'.$this->component.'/'.$this->area;
|
||||
$this->keyprefixsingle .= '/'.$this->cacheidentifier;
|
||||
$this->keyprefixsingle .= '/'.$this->get_cache_identifier();
|
||||
$identifiers = $this->get_identifiers();
|
||||
if ($identifiers) {
|
||||
foreach ($identifiers as $key => $value) {
|
||||
@@ -762,7 +747,7 @@ class cache_definition {
|
||||
'mode' => $this->mode,
|
||||
'component' => $this->component,
|
||||
'area' => $this->area,
|
||||
'siteidentifier' => $this->cacheidentifier
|
||||
'siteidentifier' => $this->get_cache_identifier()
|
||||
);
|
||||
if (!empty($this->identifiers)) {
|
||||
$identifiers = array();
|
||||
@@ -802,4 +787,13 @@ class cache_definition {
|
||||
public function get_invalidation_events() {
|
||||
return $this->invalidationevents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a cache identification string.
|
||||
*
|
||||
* @return string A string to be used as part of keys.
|
||||
*/
|
||||
protected function get_cache_identifier() {
|
||||
return cache_helper::get_site_identifier();
|
||||
}
|
||||
}
|
||||
Vendored
-2
@@ -204,7 +204,6 @@ class cache_factory {
|
||||
// Get the class. Note this is a late static binding so we need to use get_called_class.
|
||||
$definition = cache_definition::load_adhoc($mode, $component, $area, $options);
|
||||
$config = $this->create_config_instance();
|
||||
$definition->set_cache_identifier($config->get_site_identifier());
|
||||
$definition->set_identifiers($identifiers);
|
||||
$cache = $this->create_cache($definition, $identifiers);
|
||||
if ($definition->should_be_persistent()) {
|
||||
@@ -392,7 +391,6 @@ class cache_factory {
|
||||
} else {
|
||||
$definition = cache_definition::load($id, $definition, $aggregate);
|
||||
}
|
||||
$definition->set_cache_identifier($instance->get_site_identifier());
|
||||
}
|
||||
$this->definitions[$id] = $definition;
|
||||
}
|
||||
|
||||
Vendored
+31
-2
@@ -54,6 +54,13 @@ class cache_helper {
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* The site identifier used by the cache.
|
||||
* Set the first time get_site_identifier is called.
|
||||
* @var string
|
||||
*/
|
||||
protected static $siteidentifier = null;
|
||||
|
||||
/**
|
||||
* Returns true if the cache API can be initialised before Moodle has finished initialising itself.
|
||||
*
|
||||
@@ -234,7 +241,6 @@ class cache_helper {
|
||||
$factory = cache_factory::instance();
|
||||
foreach ($instance->get_definitions() as $name => $definitionarr) {
|
||||
$definition = cache_definition::load($name, $definitionarr);
|
||||
$definition->set_cache_identifier($instance->get_site_identifier());
|
||||
if ($definition->invalidates_on_event($event)) {
|
||||
// OK at this point we know that the definition has information to invalidate on the event.
|
||||
// There are two routes, either its an application cache in which case we can invalidate it now.
|
||||
@@ -305,7 +311,6 @@ class cache_helper {
|
||||
$factory = cache_factory::instance();
|
||||
foreach ($instance->get_definitions() as $name => $definitionarr) {
|
||||
$definition = cache_definition::load($name, $definitionarr);
|
||||
$definition->set_cache_identifier($instance->get_site_identifier());
|
||||
if ($definition->invalidates_on_event($event)) {
|
||||
// Create the cache.
|
||||
$cache = $factory->create_cache($definition);
|
||||
@@ -515,4 +520,28 @@ class cache_helper {
|
||||
$factory->updating_finished();
|
||||
cache_factory::reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the site identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_site_identifier() {
|
||||
if (is_null(self::$siteidentifier)) {
|
||||
$factory = cache_factory::instance();
|
||||
$config = $factory->create_config_instance();
|
||||
self::$siteidentifier = $config->get_site_identifier();
|
||||
}
|
||||
return self::$siteidentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the site version.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_site_version() {
|
||||
global $CFG;
|
||||
return (string)$CFG->version;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user