Permalink
Browse files

MDL-36466 cache: implemented functionality to disable the bulk of the…

… cache API
  • Loading branch information...
Sam Hemelryk
Sam Hemelryk committed Nov 13, 2012
1 parent 82afd05 commit 3680c61a3c489cd388202cefd605868b81730b5a
Showing with 552 additions and 4 deletions.
  1. +8 −1 cache/README.md
  2. +17 −2 cache/classes/factory.php
  3. +459 −0 cache/disabledlib.php
  4. +52 −1 cache/tests/cache_test.php
  5. +16 −0 cache/tests/locallib_test.php
@@ -68,7 +68,14 @@ While the cache API must still be functional in order for calls to it to work it
// If you disabled it using the above means you can re-enable it with:
cache_factory::reset();
Disabling the cache entirely.
Like above there are times when you want the cache to avoid initialising anything it doesn't absolutely need. Things such as installation and upgrade require this functionality.
When the cache API is disabled it is still functional however special "disabled" classes will be used instead of the regular classes that make the Cache API tick.
These disabled classes do the least work possible and through this means we avoid all manner of intialisation and configuration.
Once disabled its not recommened to reneable the Cache API. Instead if you need it, redirect.
// To disable the cache entirely call the following:
cache_factory::disable();
Cache API parts
---------------
@@ -233,7 +233,7 @@ public function create_cache(cache_definition $definition) {
* @param string $name The name of the store (must be unique remember)
* @param array $details
* @param cache_definition $definition The definition to instantiate it for.
* @return boolean
* @return boolean|cache_store
*/
public function create_store_from_config($name, array $details, cache_definition $definition) {
if (!array_key_exists($name, $this->stores)) {
@@ -413,13 +413,28 @@ public function is_disabled() {
return $this->state === self::STATE_DISABLED;
}
/**
* Disables as much of the cache API as possible.
*
* All of the magic associated with the disabled cache is wrapped into this function.
* In switching out the factory for the disabled factory it gains full control over the initialisation of objects
* and can use all of the disabled alternatives.
* Simple!
*/
public static function disable() {
global $CFG;
require_once($CFG->dirroot.'/cache/disabledlib.php');
self::$instance = null;
self::$instance = new cache_factory_disabled();
}
/**
* Returns true if the cache stores have been disabled.
*
* @return bool
*/
public function stores_disabled() {
return $this->state === self::STATE_STORES_DISABLED;
return $this->state === self::STATE_STORES_DISABLED || $this->is_disabled();
}
/**
Oops, something went wrong.

0 comments on commit 3680c61

Please sign in to comment.