MDL-36363 cache: clean up pre-integration

This commit is contained in:
Sam Hemelryk
2013-01-28 10:39:23 +13:00
parent 59ca73ff82
commit a037c943bd
10 changed files with 88 additions and 106 deletions
+22 -19
View File
@@ -135,15 +135,6 @@ 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() {
// By default, do nothing.
}
/**
* Returns the name of this store instance.
* @return string
@@ -235,23 +226,35 @@ 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 i.e. the result depends on the specific store implementation.
*
* @see instance_deleted()
* @deprecated since 2.5
*/
abstract public function cleanup();
public function cleanup() {
debugging('This function has been renamed to instance_deleted. Please update your calls.', DEBUG_DEVELOPER);
}
/**
* Performs any necessary operation when the store instance is being deleted,
* regardless the store being initialised with a definition ({@link initialise()}).
* Performs any necessary operation when the store instance has been created.
*
* @link http://tracker.moodle.org/browse/MDL-36363
* @since 2.5
*/
public function instance_created() {
// By default, do nothing.
}
/**
* Performs any necessary operation when the store instance is being deleted.
*
* This method may be called before the store has been initialised.
*
* @since 2.5
* @see cleanup()
*/
public function instance_deleted() {
// By default, do nothing
if (method_exists($this, 'cleanup')) {
// There used to be a legacy function called cleanup, it was renamed to instance delete.
// To be removed in 2.6.
$this->cleanup();
}
}
/**
+1
View File
@@ -308,6 +308,7 @@ 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']);
+10 -23
View File
@@ -46,17 +46,17 @@ class cachestore_file extends cache_store implements cache_is_key_aware, cache_i
protected $name;
/**
* The path to use for the file storage. False otherwise.
* @var string
*/
protected $filestorepath = false;
/**
* The path to use when the store instance has been initialised. False otherwise.
* The path used to store files for this store and the definition it was initialised with.
* @var string
*/
protected $path = false;
/**
* The path in which definition specific sub directories will be created for caching.
* @var string
*/
protected $filestorepath = false;
/**
* Set to true when a prescan has been performed.
* @var bool
@@ -136,6 +136,7 @@ class cachestore_file extends cache_store implements cache_is_key_aware, cache_i
}
$this->isready = $path !== false;
$this->filestorepath = $path;
// This will be updated once the store has been initialised for a definition.
$this->path = $path;
// Check if we should prescan the directory.
@@ -517,7 +518,6 @@ class cachestore_file extends cache_store implements cache_is_key_aware, cache_i
}
$this->keys = array();
}
return true;
}
@@ -609,22 +609,9 @@ class cachestore_file extends cache_store implements cache_is_key_aware, cache_i
* 1. Purges the cache directory.
* 2. Deletes the directory we created for the given definition.
*/
public function cleanup() {
$this->purge();
@rmdir($this->path);
}
/**
* Performs any necessary operation when the file store instance is being deleted,
* regardless the file store being initialised with a definition ({@link initialise()}).
*
* @see cleanup()
*/
public function instance_deleted() {
if ($this->isready && !$this->prescan) {
// Remove the content related to this file store.
$this->purge_all_definitions();
}
$this->purge_all_definitions();
@rmdir($this->filestorepath);
}
/**
+11 -12
View File
@@ -319,19 +319,18 @@ class cachestore_memcache extends cache_store implements cache_is_configurable {
/**
* Performs any necessary clean up when the store instance is being deleted.
*/
public function cleanup() {
$this->purge();
}
/**
* 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() {
$this->cleanup();
if ($this->connection) {
$connection = $this->connection;
} else {
$connection = new Memcache;
foreach ($this->servers as $server) {
$connection->addServer($server[0], $server[1], true, $server[2]);
}
}
$connection->flush();
unset($connection);
unset($this->connection);
}
/**
+15 -12
View File
@@ -401,19 +401,22 @@ class cachestore_memcached extends cache_store implements cache_is_configurable
/**
* Performs any necessary clean up when the store instance is being deleted.
*/
public function cleanup() {
$this->purge();
}
/**
* 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() {
$this->cleanup();
if ($this->connection) {
$connection = $this->connection;
} else {
$connection = new Memcached(crc32($this->name));
$servers = $connection->getServerList();
if (empty($servers)) {
foreach ($this->options as $key => $value) {
$connection->setOption($key, $value);
}
$connection->addServers($this->servers);
}
}
$connection->flush();
unset($connection);
unset($this->connection);
}
/**
+16 -13
View File
@@ -67,7 +67,7 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
* The Connection object
* @var Mongo
*/
protected $connection;
protected $connection = false;
/**
* The Database Object
@@ -439,19 +439,22 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
/**
* Performs any necessary clean up when the store instance is being deleted.
*/
public function cleanup() {
$this->purge();
}
/**
* 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() {
$this->cleanup();
// We can't use purge here that acts upon a collection.
// Instead we must drop the named database.
if ($this->connection) {
$connection = $this->connection;
} else {
$connection = new Mongo($this->server, $this->options);
}
$database = $connection->selectDB($this->databasename);
$database->drop();
$connection = null;
$database = null;
// Explicitly unset things to cause a close.
$this->collection = null;
$this->database = null;
$this->connection = null;
}
/**
+1 -12
View File
@@ -375,19 +375,8 @@ class cachestore_session extends session_data_store implements cache_is_key_awar
/**
* Performs any necessary clean up when the store instance is being deleted.
*/
public function cleanup() {
$this->purge();
}
/**
* 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() {
$this->cleanup();
$this->purge();
}
/**
+1 -12
View File
@@ -372,19 +372,8 @@ class cachestore_static extends static_data_store implements cache_is_key_aware
/**
* Performs any necessary clean up when the store instance is being deleted.
*/
public function cleanup() {
$this->purge();
}
/**
* 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() {
$this->cleanup();
$this->purge();
}
/**
+3 -3
View File
@@ -100,7 +100,7 @@ foreach (get_plugin_list_with_file('cachestore', 'lib.php', true) as $plugin =>
}
$result[5] = sprintf('%01.4f', microtime(true) - $start);
$applicationtable->data[] = $result;
$store->cleanup();
$store->instance_deleted();
}
}
@@ -136,7 +136,7 @@ foreach (get_plugin_list_with_file('cachestore', 'lib.php', true) as $plugin =>
}
$result[5] = sprintf('%01.4f', microtime(true) - $start);
$sessiontable->data[] = $result;
$store->cleanup();
$store->instance_deleted();
}
}
@@ -172,7 +172,7 @@ foreach (get_plugin_list_with_file('cachestore', 'lib.php', true) as $plugin =>
}
$result[5] = sprintf('%01.4f', microtime(true) - $start);
$requesttable->data[] = $result;
$store->cleanup();
$store->instance_deleted();
}
}
+8
View File
@@ -0,0 +1,8 @@
This files describes API changes in /cache/stores/* - cache store plugins.
Information provided here is intended especially for developers.
=== 2.5 ===
* cleanup method renamed to instance_deleted.
It is now called when the store is deleted as all comments suggested anyway.
* instance_created method added.
It is called when the store is created for the very first time.