Permalink
Browse files

MDL-41292 cache: only update identifiers if they change

  • Loading branch information...
1 parent 47358bd commit 44eaae9610c467a876b6faefaf8ea0cd7ebabdf8 @mr-russ mr-russ committed with stronk7 Aug 19, 2013
Showing with 16 additions and 2 deletions.
  1. +16 −2 cache/classes/definition.php
@@ -256,7 +256,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
@@ -582,6 +582,9 @@ public function uses_simple_keys() {
* @return array
*/
public function get_identifiers() {
+ if (!isset($this->identifiers)) {
+ return array();
+ }
return $this->identifiers;
}
@@ -694,11 +697,22 @@ public function get_data_source() {
* @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 (!array_key_exists($identifier, $identifiers)) {
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;
}
@@ -820,7 +834,7 @@ public function generate_multi_key_parts() {
'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');

0 comments on commit 44eaae9

Please sign in to comment.