mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 16:04:25 +02:00
MDL-41292 cache: only update identifiers if they change
This commit is contained in:
parent
c36a2401ab
commit
0dd7c711c5
18
cache/classes/definition.php
vendored
18
cache/classes/definition.php
vendored
@ -281,7 +281,7 @@ class cache_definition {
|
||||
* An array of identifiers provided to this cache when it was initialised.
|
||||
* @var array
|
||||
*/
|
||||
protected $identifiers = array();
|
||||
protected $identifiers = null;
|
||||
|
||||
/**
|
||||
* Key prefix for use with single key cache stores
|
||||
@ -654,6 +654,9 @@ class cache_definition {
|
||||
* @return array
|
||||
*/
|
||||
public function get_identifiers() {
|
||||
if (!isset($this->identifiers)) {
|
||||
return array();
|
||||
}
|
||||
return $this->identifiers;
|
||||
}
|
||||
|
||||
@ -766,11 +769,22 @@ class cache_definition {
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public function set_identifiers(array $identifiers = array()) {
|
||||
// If we are setting the exact same identifiers then just return as nothing really changed.
|
||||
// We don't care about order as cache::make will use the same definition order all the time.
|
||||
if ($identifiers === $this->identifiers) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->requireidentifiers as $identifier) {
|
||||
if (!isset($identifiers[$identifier])) {
|
||||
throw new coding_exception('Identifier required for cache has not been provided: '.$identifier);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->identifiers === null) {
|
||||
// Initialize identifiers if they have not been.
|
||||
$this->identifiers = array();
|
||||
}
|
||||
foreach ($identifiers as $name => $value) {
|
||||
$this->identifiers[$name] = (string)$value;
|
||||
}
|
||||
@ -893,7 +907,7 @@ class cache_definition {
|
||||
'area' => $this->area,
|
||||
'siteidentifier' => $this->get_cache_identifier()
|
||||
);
|
||||
if (!empty($this->identifiers)) {
|
||||
if (isset($this->identifiers) && !empty($this->identifiers)) {
|
||||
$identifiers = array();
|
||||
foreach ($this->identifiers as $key => $value) {
|
||||
$identifiers[] = htmlentities($key, ENT_QUOTES, 'UTF-8').'='.htmlentities($value, ENT_QUOTES, 'UTF-8');
|
||||
|
Loading…
x
Reference in New Issue
Block a user