MDL-36363 Added cache_store::instance_created() and cache_store::instance_deleted()

This commit is contained in:
Matteo Scaramuccia 2012-12-02 10:48:18 +01:00 committed by Sam Hemelryk
parent b3778a0dec
commit 730cf5acbc
2 changed files with 31 additions and 0 deletions

View File

@ -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.
*

9
cache/locallib.php vendored
View File

@ -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;