Permalink
Browse files

MDL-36363 Added cache_store::instance_created() and cache_store::inst…

…ance_deleted()
  • Loading branch information...
1 parent df93b15 commit 5d7411e92bab4bcd89402ca28a9a4a4533e5a9ac @scara scara committed with Sam Hemelryk Dec 2, 2012
Showing with 31 additions and 0 deletions.
  1. +22 −0 cache/classes/store.php
  2. +9 −0 cache/locallib.php
View
22 cache/classes/store.php
@@ -136,6 +136,13 @@ public static function initialise_test_instance(cache_definition $definition);
abstract public function __construct($name, array $configuration = array());
/**
+ * Performs any necessary operation when the store instance has been created.
+ *
+ * @link http://tracker.moodle.org/browse/MDL-36363
+ */
+ public function instance_created() {}
+
+ /**
* Returns the name of this store instance.
* @return string
*/
@@ -225,10 +232,25 @@ public static function initialise_test_instance(cache_definition $definition);
/**
* Performs any necessary clean up when the store instance is being deleted.
+ *
+ * Please note that if the store has been already initialised with
+ * a definition ({@link initialise()}), cleanup will be performed against the scope
+ * of that definition.
+ *
+ * @see instance_deleted()
*/
abstract public function cleanup();
/**
+ * Performs any necessary operation when the store instance is being deleted,
+ * regardless the store being initialised with a definition ({@link initialise()}).
+ *
+ * @link http://tracker.moodle.org/browse/MDL-36363
+ * @see cleanup()
+ */
+ public function instance_deleted() {}
+
+ /**
* Returns true if the user can add an instance of the store plugin.
*
* @return bool
View
9 cache/locallib.php
@@ -178,6 +178,10 @@ public function add_store_instance($name, $plugin, array $configuration = array(
$this->configstores[$name]['lock'] = $configuration['lock'];
unset($this->configstores[$name]['configuration']['lock']);
}
+ // Call instance_created()
+ $store = new $class($name, $this->configstores[$name]['configuration']);
+ $store->instance_created();
+
$this->config_save();
return true;
}
@@ -304,6 +308,11 @@ public function delete_store_instance($name) {
throw new cache_exception('You cannot delete a cache store that has definition mappings.');
}
}
+ // Call instance_deleted()
+ $class = 'cachestore_'.$this->configstores[$name]['plugin'];
+ $store = new $class($name, $this->configstores[$name]['configuration']);
+ $store->instance_deleted();
+
unset($this->configstores[$name]);
$this->config_save();
return true;

0 comments on commit 5d7411e

Please sign in to comment.