diff --git a/cache/classes/store.php b/cache/classes/store.php index dca65dafc8f..e3326774237 100644 --- a/cache/classes/store.php +++ b/cache/classes/store.php @@ -135,6 +135,13 @@ abstract class cache_store implements cache_store_interface { */ 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,9 +232,24 @@ abstract class cache_store implements cache_store_interface { /** * 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. * diff --git a/cache/locallib.php b/cache/locallib.php index 76888b7e782..4982719d66d 100644 --- a/cache/locallib.php +++ b/cache/locallib.php @@ -178,6 +178,10 @@ class cache_config_writer extends cache_config { $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 @@ class cache_config_writer extends cache_config { 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;