mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-40903 cache: renamed persistcache to staticacceleration
This commit is contained in:
parent
fb0eaa3fda
commit
d074fb091d
12
cache/README.md
vendored
12
cache/README.md
vendored
@ -24,8 +24,8 @@ A definition:
|
||||
'overrideclassfile' => null, // Optional
|
||||
'datasource' => null, // Optional
|
||||
'datasourcefile' => null, // Optional
|
||||
'persistentdata' => false, // Optional
|
||||
'persistentmaxsize' => false, // Optional
|
||||
'staticacceleration' => false, // Optional
|
||||
'staticaccelerationsize' => false, // Optional
|
||||
'ttl' => 0, // Optional
|
||||
'mappingsonly' => false // Optional
|
||||
'invalidationevents' => array( // Optional
|
||||
@ -144,8 +144,8 @@ The following optional settings can also be defined:
|
||||
* overrideclassfile - Included if required when using the overrideclass param.
|
||||
* datasource - If provided this class will be used as a data source for the definition. It must implement the cache_data_source interface.
|
||||
* datasourcefile - Included if required when using the datasource param.
|
||||
* persistentdata - Any data passing through the cache will be held onto to make subsequent requests for it faster.
|
||||
* persistentmaxsize - If set to an int this will be the maximum number of items stored in the persistent data cache.
|
||||
* staticacceleration - Any data passing through the cache will be held onto to make subsequent requests for it faster.
|
||||
* staticaccelerationsize - If set to an int this will be the maximum number of items stored in the static acceleration array.
|
||||
* ttl - Can be used to set a ttl value for data being set for this cache.
|
||||
* mappingsonly - This definition can only be used if there is a store mapping for it. More on this later.
|
||||
* invalidationevents - An array of events that should trigger this cache to invalidate.
|
||||
@ -154,10 +154,10 @@ The following optional settings can also be defined:
|
||||
|
||||
It's important to note that internally the definition is also aware of the component. This is picked up when the definition is read, based upon the location of the caches.php file.
|
||||
|
||||
The persistentdata option.
|
||||
The staticacceleration option.
|
||||
Data passed to or retrieved from the loader and its chained loaders gets cached by the instance.
|
||||
Because it caches key=>value data it avoids the need to re-fetch things from stores after the first request. Its good for performance, bad for memory.
|
||||
Memeory use can be controlled by setting the persistentmaxsize option.
|
||||
Memory use can be controlled by setting the staticaccelerationsize option.
|
||||
It should be used sparingly.
|
||||
|
||||
The mappingsonly option.
|
||||
|
79
cache/classes/definition.php
vendored
79
cache/classes/definition.php
vendored
@ -75,14 +75,14 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* [string] A class to use as the data loader for this definition.
|
||||
* Any class used here must inherit the cache_data_loader interface.
|
||||
* + datasourcefile
|
||||
* [string] Suplements the above setting indicated the file containing the class to be used. This file is included when
|
||||
* [string] Supplements the above setting indicating the file containing the class to be used. This file is included when
|
||||
* required.
|
||||
* + persistentdata
|
||||
* + staticacceleration
|
||||
* The cache loader will keep an array of the items set and retrieved to the cache during the request.
|
||||
* Consider using this setting when you know that there are going to be many calls to the cache for the same information.
|
||||
* Requests for data in this array will be ultra fast, but it will cost memory.
|
||||
* + persistentmaxsize
|
||||
* [int] This supplements the above setting by limiting the number of items in the caches persistent array of items.
|
||||
* + staticaccelerationsize
|
||||
* [int] This supplements the above setting by limiting the number of items in the static acceleration array.
|
||||
* Tweaking this setting lower will allow you to minimise the memory implications above while hopefully still managing to
|
||||
* offset calls to the cache store.
|
||||
* + ttl
|
||||
@ -251,13 +251,13 @@ class cache_definition {
|
||||
* Set to true if the cache should hold onto items passing through it to speed up subsequent requests.
|
||||
* @var bool
|
||||
*/
|
||||
protected $persistentdata = false;
|
||||
protected $staticacceleration = false;
|
||||
|
||||
/**
|
||||
* The persistent item array max size.
|
||||
* The maximum number of items that static acceleration cache should hold onto.
|
||||
* @var int
|
||||
*/
|
||||
protected $persistentmaxsize = false;
|
||||
protected $staticaccelerationsize = false;
|
||||
|
||||
/**
|
||||
* The TTL for data in this cache. Please don't use this, instead use event driven invalidation.
|
||||
@ -358,8 +358,8 @@ class cache_definition {
|
||||
$overrideclassfile = null;
|
||||
$datasource = null;
|
||||
$datasourcefile = null;
|
||||
$persistentdata = false;
|
||||
$persistentmaxsize = false;
|
||||
$staticacceleration = false;
|
||||
$staticaccelerationsize = false;
|
||||
$ttl = 0;
|
||||
$mappingsonly = false;
|
||||
$invalidationevents = array();
|
||||
@ -415,13 +415,17 @@ class cache_definition {
|
||||
|
||||
if (array_key_exists('persistent', $definition)) {
|
||||
// Ahhh this is the legacy persistent option.
|
||||
$persistentdata = (bool)$definition['persistent'];
|
||||
$staticacceleration = (bool)$definition['persistent'];
|
||||
}
|
||||
if (array_key_exists('persistentdata', $definition)) {
|
||||
$persistentdata = (bool)$definition['persistentdata'];
|
||||
if (array_key_exists('staticacceleration', $definition)) {
|
||||
$staticacceleration = (bool)$definition['staticacceleration'];
|
||||
}
|
||||
if (array_key_exists('persistentmaxsize', $definition)) {
|
||||
$persistentmaxsize = (int)$definition['persistentmaxsize'];
|
||||
// Ahhh this is the legacy persistentmaxsize option.
|
||||
$staticaccelerationsize = (int)$definition['persistentmaxsize'];
|
||||
}
|
||||
if (array_key_exists('staticaccelerationsize', $definition)) {
|
||||
$staticaccelerationsize = (int)$definition['staticaccelerationsize'];
|
||||
}
|
||||
if (array_key_exists('ttl', $definition)) {
|
||||
$ttl = (int)$definition['ttl'];
|
||||
@ -517,8 +521,8 @@ class cache_definition {
|
||||
$cachedefinition->datasource = $datasource;
|
||||
$cachedefinition->datasourcefile = $datasourcefile;
|
||||
$cachedefinition->datasourceaggregate = $datasourceaggregate;
|
||||
$cachedefinition->persistentdata = $persistentdata;
|
||||
$cachedefinition->persistentmaxsize = $persistentmaxsize;
|
||||
$cachedefinition->staticacceleration = $staticacceleration;
|
||||
$cachedefinition->staticaccelerationsize = $staticaccelerationsize;
|
||||
$cachedefinition->ttl = $ttl;
|
||||
$cachedefinition->mappingsonly = $mappingsonly;
|
||||
$cachedefinition->invalidationevents = $invalidationevents;
|
||||
@ -542,8 +546,8 @@ class cache_definition {
|
||||
* - simplekeys : Set to true if the keys you will use are a-zA-Z0-9_
|
||||
* - simpledata : Set to true if the type of the data you are going to store is scalar, or an array of scalar vars
|
||||
* - overrideclass : The class to use as the loader.
|
||||
* - persistentdata : If set to true the cache will hold onto data passing through it.
|
||||
* - persistentmaxsize : Set it to an int to limit the size of the persistentdata cache.
|
||||
* - staticacceleration : If set to true the cache will hold onto data passing through it.
|
||||
* - staticaccelerationsize : Set it to an int to limit the size of the staticacceleration cache.
|
||||
* @return cache_application|cache_session|cache_request
|
||||
*/
|
||||
public static function load_adhoc($mode, $component, $area, array $options = array()) {
|
||||
@ -561,13 +565,13 @@ class cache_definition {
|
||||
}
|
||||
if (!empty($options['persistent'])) {
|
||||
// Ahhh this is the legacy persistent option.
|
||||
$definition['persistentdata'] = (bool)$options['persistent'];
|
||||
$definition['staticacceleration'] = (bool)$options['persistent'];
|
||||
}
|
||||
if (!empty($options['persistentdata'])) {
|
||||
$definition['persistentdata'] = (bool)$options['persistentdata'];
|
||||
if (!empty($options['staticacceleration'])) {
|
||||
$definition['staticacceleration'] = (bool)$options['staticacceleration'];
|
||||
}
|
||||
if (!empty($options['persistentmaxsize'])) {
|
||||
$definition['persistentmaxsize'] = (int)$options['persistentmaxsize'];
|
||||
if (!empty($options['staticaccelerationsize'])) {
|
||||
$definition['staticaccelerationsize'] = (int)$options['staticaccelerationsize'];
|
||||
}
|
||||
if (!empty($options['overrideclass'])) {
|
||||
$definition['overrideclass'] = $options['overrideclass'];
|
||||
@ -796,14 +800,15 @@ class cache_definition {
|
||||
/**
|
||||
* Returns true if this definitions cache should be made persistent.
|
||||
*
|
||||
* Please call data_should_be_persistent instead.
|
||||
* Please call {@link cache_definition::use_static_acceleration()} instead.
|
||||
*
|
||||
* @see cache_definition::use_static_acceleration()
|
||||
* @deprecated since 2.6
|
||||
* @return bool
|
||||
*/
|
||||
public function should_be_persistent() {
|
||||
debugging('should_be_persistent has been deprecated please call data_should_be_persistent instead', DEBUG_DEVELOPER);
|
||||
return $this->data_should_be_persistent();
|
||||
debugging('Please upgrade your code to use cache_definition::use_static_acceleration', DEBUG_DEVELOPER);
|
||||
return $this->use_static_acceleration();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -814,20 +819,34 @@ class cache_definition {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function data_should_be_persistent() {
|
||||
public function use_static_acceleration() {
|
||||
if ($this->mode === cache_store::MODE_REQUEST) {
|
||||
// Request caches should never use persistent data - it just doesn't make sense.
|
||||
// Request caches should never use static acceleration - it just doesn't make sense.
|
||||
return false;
|
||||
}
|
||||
return $this->persistentdata || $this->mode === cache_store::MODE_SESSION;
|
||||
return $this->staticacceleration || $this->mode === cache_store::MODE_SESSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the max size for the persistent item array in the cache.
|
||||
* Returns the max size for the static acceleration array.
|
||||
*
|
||||
* Please call {@link cache_definition::get_static_acceleration_size()} instead.
|
||||
*
|
||||
* @see cache_definition::get_static_acceleration_size()
|
||||
* @deprecated since 2.6
|
||||
* @return int
|
||||
*/
|
||||
public function get_persistent_max_size() {
|
||||
return $this->persistentmaxsize;
|
||||
debugging('Please upgrade your code to call cache_definition::get_static_acceleration_size', DEBUG_DEVELOPER);
|
||||
return $this->get_static_acceleration_size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the max size for the static acceleration array.
|
||||
* @return int
|
||||
*/
|
||||
public function get_static_acceleration_size() {
|
||||
return $this->staticaccelerationsize;
|
||||
}
|
||||
|
||||
/**
|
||||
|
17
cache/classes/dummystore.php
vendored
17
cache/classes/dummystore.php
vendored
@ -46,14 +46,15 @@ class cachestore_dummy extends cache_store {
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Gets set to true if this store is going to persist data.
|
||||
* This happens when the definition doesn't require it as the loader will not be persisting information and something has to.
|
||||
* Gets set to true if this store is going to store data.
|
||||
* This happens when the definition doesn't require static acceleration as the loader will not be storing information and
|
||||
* something has to.
|
||||
* @var bool
|
||||
*/
|
||||
protected $persist = false;
|
||||
|
||||
/**
|
||||
* The persistent store array
|
||||
* The stored data array
|
||||
* @var array
|
||||
*/
|
||||
protected $store = array();
|
||||
@ -106,13 +107,13 @@ class cachestore_dummy extends cache_store {
|
||||
* @param cache_definition $definition
|
||||
*/
|
||||
public function initialise(cache_definition $definition) {
|
||||
// If the definition isn't persistent then we need to be persistent here.
|
||||
// If the definition isn't using static acceleration then we need to be store data here.
|
||||
// The reasoning behind this is that:
|
||||
// - If the definition is persistent then the cache loader is going to
|
||||
// store things in its persistent cache.
|
||||
// - If the definition is not persistent then the cache loader won't try to store anything
|
||||
// - If the definition is using static acceleration then the cache loader is going to
|
||||
// store things in its static array.
|
||||
// - If the definition is not using static acceleration then the cache loader won't try to store anything
|
||||
// and we will need to store it here in order to make sure it is accessible.
|
||||
$this->persist = !$definition->data_should_be_persistent();
|
||||
$this->persist = !$definition->use_static_acceleration();
|
||||
}
|
||||
|
||||
/**
|
||||
|
14
cache/classes/factory.php
vendored
14
cache/classes/factory.php
vendored
@ -208,7 +208,8 @@ class cache_factory {
|
||||
* @param array $options An array of options, available options are:
|
||||
* - simplekeys : Set to true if the keys you will use are a-zA-Z0-9_
|
||||
* - simpledata : Set to true if the type of the data you are going to store is scalar, or an array of scalar vars
|
||||
* - persistent : If set to true the cache will persist construction requests.
|
||||
* - staticacceleration : If set to true the cache will hold onto data passing through it.
|
||||
* - staticaccelerationsize : The maximum number of items to hold onto for acceleration purposes.
|
||||
* @return cache_application|cache_session|cache_request
|
||||
*/
|
||||
public function create_cache_from_params($mode, $component, $area, array $identifiers = array(), array $options = array()) {
|
||||
@ -304,6 +305,15 @@ class cache_factory {
|
||||
return $this->definitionstores[$id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cache instances that have been used within this request.
|
||||
* @since 2.6
|
||||
* @return array
|
||||
*/
|
||||
public function get_caches_in_use() {
|
||||
return $this->cachesfromdefinitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a cache config instance with the ability to write if required.
|
||||
*
|
||||
@ -592,7 +602,7 @@ class cache_factory {
|
||||
* </code>
|
||||
*/
|
||||
public static function disable_stores() {
|
||||
// First reset to clear any persistent caches.
|
||||
// First reset to clear any static acceleration array.
|
||||
$factory = self::instance();
|
||||
$factory->reset_cache_instances();
|
||||
$factory->set_state(self::STATE_STORES_DISABLED);
|
||||
|
152
cache/classes/loaders.php
vendored
152
cache/classes/loaders.php
vendored
@ -93,43 +93,46 @@ class cache implements cache_loader {
|
||||
private $supportsnativettl = null;
|
||||
|
||||
/**
|
||||
* Gets set to true if the cache is going to be using the build in static "persist" cache.
|
||||
* The persist cache statically caches items used during the lifetime of the request. This greatly speeds up interaction
|
||||
* Gets set to true if the cache is going to be using a static array for acceleration.
|
||||
* The array statically caches items used during the lifetime of the request. This greatly speeds up interaction
|
||||
* with the cache in areas where it will be repetitively hit for the same information such as with strings.
|
||||
* There are several other variables to control how this persist cache works.
|
||||
* There are several other variables to control how this static acceleration array works.
|
||||
* @var bool
|
||||
*/
|
||||
private $persistdata = false;
|
||||
private $staticacceleration = false;
|
||||
|
||||
/**
|
||||
* The persist cache itself.
|
||||
* The static acceleration array.
|
||||
* Items will be stored in this cache as they were provided. This ensure there is no unnecessary processing taking place.
|
||||
* @var array
|
||||
*/
|
||||
private $persistcache = array();
|
||||
private $staticaccelerationarray = array();
|
||||
|
||||
/**
|
||||
* The number of items in the persist cache. Avoids count calls like you wouldn't believe.
|
||||
* The number of items in the static acceleration array. Avoids count calls like you wouldn't believe.
|
||||
* @var int
|
||||
*/
|
||||
private $persistcount = 0;
|
||||
private $staticaccelerationcount = 0;
|
||||
|
||||
/**
|
||||
* An array containing just the keys being used in the persist cache.
|
||||
* This seems redundant perhaps but is used when managing the size of the persist cache.
|
||||
* An array containing just the keys being used in the static acceleration array.
|
||||
* This seems redundant perhaps but is used when managing the size of the static acceleration array.
|
||||
* Items are added to the end of the array and the when we need to reduce the size of the cache we use the
|
||||
* key that is first on this array.
|
||||
* @var array
|
||||
*/
|
||||
private $persistkeys = array();
|
||||
private $staticaccelerationkeys = array();
|
||||
|
||||
/**
|
||||
* The maximum size of the persist cache. If set to false there is no max size.
|
||||
* Caches that make use of the persist cache should seriously consider setting this to something reasonably small, but
|
||||
* The maximum size of the static acceleration array.
|
||||
*
|
||||
* If set to false there is no max size.
|
||||
* Caches that make use of static acceleration should seriously consider setting this to something reasonably small, but
|
||||
* still large enough to offset repetitive calls.
|
||||
*
|
||||
* @var int|false
|
||||
*/
|
||||
private $persistmaxsize = false;
|
||||
private $staticaccelerationsize = false;
|
||||
|
||||
/**
|
||||
* Gets set to true during initialisation if the definition is making use of a ttl.
|
||||
@ -181,7 +184,8 @@ class cache implements cache_loader {
|
||||
* @param array $options An array of options, available options are:
|
||||
* - simplekeys : Set to true if the keys you will use are a-zA-Z0-9_
|
||||
* - simpledata : Set to true if the type of the data you are going to store is scalar, or an array of scalar vars
|
||||
* - persistent : If set to true the cache will persist construction requests.
|
||||
* - staticacceleration : If set to true the cache will hold onto data passing through it.
|
||||
* - staticaccelerationsize : The max size for the static acceleration array.
|
||||
* @return cache_application|cache_session|cache_store
|
||||
*/
|
||||
public static function make_from_params($mode, $component, $area, array $identifiers = array(), array $options = array()) {
|
||||
@ -218,9 +222,9 @@ class cache implements cache_loader {
|
||||
$this->datasource = $loader;
|
||||
}
|
||||
$this->definition->generate_definition_hash();
|
||||
$this->persistdata = $this->definition->data_should_be_persistent();
|
||||
if ($this->persistdata) {
|
||||
$this->persistmaxsize = $this->definition->get_persistent_max_size();
|
||||
$this->staticacceleration = $this->definition->use_static_acceleration();
|
||||
if ($this->staticacceleration) {
|
||||
$this->staticaccelerationsize = $this->definition->get_static_acceleration_size();
|
||||
}
|
||||
$this->hasattl = ($this->definition->get_ttl() > 0);
|
||||
}
|
||||
@ -228,7 +232,7 @@ class cache implements cache_loader {
|
||||
/**
|
||||
* Used to inform the loader of its state as a sub loader, or as the top of the chain.
|
||||
*
|
||||
* This is important as it ensures that we do not have more than one loader keeping persistent data.
|
||||
* This is important as it ensures that we do not have more than one loader keeping static acceleration data.
|
||||
* Subloaders need to be "pure" loaders in the sense that they are used to store and retrieve information from stores or the
|
||||
* next loader/data source in the chain.
|
||||
* Nothing fancy, nothing flash.
|
||||
@ -238,14 +242,14 @@ class cache implements cache_loader {
|
||||
protected function set_is_sub_loader($setting = true) {
|
||||
if ($setting) {
|
||||
$this->subloader = true;
|
||||
// Subloaders should not keep persistent data.
|
||||
$this->persistdata = false;
|
||||
$this->persistmaxsize = false;
|
||||
// Subloaders should not keep static acceleration data.
|
||||
$this->staticacceleration = false;
|
||||
$this->staticaccelerationsize = false;
|
||||
} else {
|
||||
$this->subloader = true;
|
||||
$this->persistdata = $this->definition->data_should_be_persistent();
|
||||
if ($this->persistdata) {
|
||||
$this->persistmaxsize = $this->definition->get_persistent_max_size();
|
||||
$this->staticacceleration = $this->definition->use_static_acceleration();
|
||||
if ($this->staticacceleration) {
|
||||
$this->staticaccelerationsize = $this->definition->get_static_acceleration_size();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -276,7 +280,7 @@ class cache implements cache_loader {
|
||||
public function get($key, $strictness = IGNORE_MISSING) {
|
||||
// 1. Parse the key.
|
||||
$parsedkey = $this->parse_key($key);
|
||||
// 2. Get it from the persist cache if we can (only when persist is enabled and it has already been requested/set).
|
||||
// 2. Get it from the static acceleration array if we can (only when it is enabled and it has already been requested/set).
|
||||
$result = false;
|
||||
if ($this->is_using_persist_cache()) {
|
||||
$result = $this->get_from_persist_cache($parsedkey);
|
||||
@ -291,7 +295,7 @@ class cache implements cache_loader {
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
// 3. Get it from the store. Obviously wasn't in the persist cache.
|
||||
// 3. Get it from the store. Obviously wasn't in the static acceleration array.
|
||||
$result = $this->store->get($parsedkey);
|
||||
if ($result !== false) {
|
||||
if ($result instanceof cache_ttl_wrapper) {
|
||||
@ -607,7 +611,7 @@ class cache implements cache_loader {
|
||||
}
|
||||
$data = array();
|
||||
$simulatettl = $this->has_a_ttl() && !$this->store_supports_native_ttl();
|
||||
$usepersistcache = $this->is_using_persist_cache();
|
||||
$usestaticaccelerationarray = $this->is_using_persist_cache();
|
||||
foreach ($keyvaluearray as $key => $value) {
|
||||
if (is_object($value) && $value instanceof cacheable_object) {
|
||||
$value = new cache_cached_object($value);
|
||||
@ -625,7 +629,7 @@ class cache implements cache_loader {
|
||||
'key' => $this->parse_key($key),
|
||||
'value' => $value
|
||||
);
|
||||
if ($usepersistcache) {
|
||||
if ($usestaticaccelerationarray) {
|
||||
$this->set_in_persist_cache($data[$key]['key'], $value);
|
||||
}
|
||||
}
|
||||
@ -659,7 +663,7 @@ class cache implements cache_loader {
|
||||
public function has($key, $tryloadifpossible = false) {
|
||||
$parsedkey = $this->parse_key($key);
|
||||
if ($this->is_in_persist_cache($parsedkey)) {
|
||||
// Hoorah, that was easy. It exists in the persist cache so we definitely have it.
|
||||
// Hoorah, that was easy. It exists in the static acceleration array so we definitely have it.
|
||||
return true;
|
||||
}
|
||||
if ($this->has_a_ttl() && !$this->store_supports_native_ttl()) {
|
||||
@ -801,11 +805,11 @@ class cache implements cache_loader {
|
||||
* @return bool True on success, false otherwise
|
||||
*/
|
||||
public function purge() {
|
||||
// 1. Purge the persist cache.
|
||||
$this->persistcache = array();
|
||||
if ($this->persistmaxsize !== false) {
|
||||
$this->persistkeys = array();
|
||||
$this->persistcount = 0;
|
||||
// 1. Purge the static acceleration array.
|
||||
$this->staticaccelerationarray = array();
|
||||
if ($this->staticaccelerationsize !== false) {
|
||||
$this->staticaccelerationkeys = array();
|
||||
$this->staticaccelerationcount = 0;
|
||||
}
|
||||
// 2. Purge the store.
|
||||
$this->store->purge();
|
||||
@ -915,16 +919,16 @@ class cache implements cache_loader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this cache is making use of the persist cache.
|
||||
* Returns true if this cache is making use of the static acceleration array.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_using_persist_cache() {
|
||||
return $this->persistdata;
|
||||
return $this->staticacceleration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the requested key exists within the persist cache.
|
||||
* Returns true if the requested key exists within the static acceleration array.
|
||||
*
|
||||
* @param string $key The parsed key
|
||||
* @return bool
|
||||
@ -936,20 +940,21 @@ class cache implements cache_loader {
|
||||
}
|
||||
// This could be written as a single line, however it has been split because the ttl check is faster than the instanceof
|
||||
// and has_expired calls.
|
||||
if (!$this->persistdata || !array_key_exists($key, $this->persistcache)) {
|
||||
if (!$this->staticacceleration || !array_key_exists($key, $this->staticaccelerationarray)) {
|
||||
return false;
|
||||
}
|
||||
if ($this->has_a_ttl() && $this->store_supports_native_ttl()) {
|
||||
return !($this->persistcache[$key] instanceof cache_ttl_wrapper && $this->persistcache[$key]->has_expired());
|
||||
return !($this->staticaccelerationarray[$key] instanceof cache_ttl_wrapper &&
|
||||
$this->staticaccelerationarray[$key]->has_expired());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the item from the persist cache if it exists there.
|
||||
* Returns the item from the static acceleration array if it exists there.
|
||||
*
|
||||
* @param string $key The parsed key
|
||||
* @return mixed|false The data from the persist cache or false if it wasn't there.
|
||||
* @return mixed|false The data from the static acceleration array or false if it wasn't there.
|
||||
*/
|
||||
protected function get_from_persist_cache($key) {
|
||||
// This method of checking if an array was supplied is faster than is_array.
|
||||
@ -958,12 +963,12 @@ class cache implements cache_loader {
|
||||
}
|
||||
// This isset check is faster than array_key_exists but will return false
|
||||
// for null values, meaning null values will come from backing store not
|
||||
// the persist cache. We think this okay because null usage should be
|
||||
// the static acceleration array. We think this okay because null usage should be
|
||||
// very rare (see comment in MDL-39472).
|
||||
if (!$this->persistdata || !isset($this->persistcache[$key])) {
|
||||
if (!$this->staticacceleration || !isset($this->staticaccelerationarray[$key])) {
|
||||
$result = false;
|
||||
} else {
|
||||
$data = $this->persistcache[$key];
|
||||
$data = $this->staticaccelerationarray[$key];
|
||||
if (!$this->has_a_ttl() || !$data instanceof cache_ttl_wrapper) {
|
||||
if ($data instanceof cache_cached_object) {
|
||||
$data = $data->restore_object();
|
||||
@ -981,28 +986,28 @@ class cache implements cache_loader {
|
||||
}
|
||||
if ($result) {
|
||||
if ($this->perfdebug) {
|
||||
cache_helper::record_cache_hit('** static persist **', $this->definition->get_id());
|
||||
cache_helper::record_cache_hit('** static acceleration **', $this->definition->get_id());
|
||||
}
|
||||
if ($this->persistmaxsize > 1 && $this->persistcount > 1) {
|
||||
// Check to see if this is the last item on the persist keys array.
|
||||
if (end($this->persistkeys) !== $key) {
|
||||
if ($this->staticaccelerationsize > 1 && $this->staticaccelerationcount > 1) {
|
||||
// Check to see if this is the last item on the static acceleration keys array.
|
||||
if (end($this->staticaccelerationkeys) !== $key) {
|
||||
// It isn't the last item.
|
||||
// Move the item to the end of the array so that it is last to be removed.
|
||||
unset($this->persistkeys[$key]);
|
||||
$this->persistkeys[$key] = $key;
|
||||
unset($this->staticaccelerationkeys[$key]);
|
||||
$this->staticaccelerationkeys[$key] = $key;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
} else {
|
||||
if ($this->perfdebug) {
|
||||
cache_helper::record_cache_miss('** static persist **', $this->definition->get_id());
|
||||
cache_helper::record_cache_miss('** static acceleration **', $this->definition->get_id());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a key value pair into the persist cache.
|
||||
* Sets a key value pair into the static acceleration array.
|
||||
*
|
||||
* @param string $key The parsed key
|
||||
* @param mixed $data
|
||||
@ -1013,36 +1018,36 @@ class cache implements cache_loader {
|
||||
if ($key === (array)$key) {
|
||||
$key = $key['key'];
|
||||
}
|
||||
if ($this->persistmaxsize !== false && isset($this->persistkeys[$key])) {
|
||||
$this->persistcount--;
|
||||
unset($this->persistkeys[$key]);
|
||||
if ($this->staticaccelerationsize !== false && isset($this->staticaccelerationkeys[$key])) {
|
||||
$this->staticaccelerationcount--;
|
||||
unset($this->staticaccelerationkeys[$key]);
|
||||
}
|
||||
$this->persistcache[$key] = $data;
|
||||
if ($this->persistmaxsize !== false) {
|
||||
$this->persistcount++;
|
||||
$this->persistkeys[$key] = $key;
|
||||
if ($this->persistcount > $this->persistmaxsize) {
|
||||
$dropkey = array_shift($this->persistkeys);
|
||||
unset($this->persistcache[$dropkey]);
|
||||
$this->persistcount--;
|
||||
$this->staticaccelerationarray[$key] = $data;
|
||||
if ($this->staticaccelerationsize !== false) {
|
||||
$this->staticaccelerationcount++;
|
||||
$this->staticaccelerationkeys[$key] = $key;
|
||||
if ($this->staticaccelerationcount > $this->staticaccelerationsize) {
|
||||
$dropkey = array_shift($this->staticaccelerationkeys);
|
||||
unset($this->staticaccelerationarray[$dropkey]);
|
||||
$this->staticaccelerationcount--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an item from the persist cache.
|
||||
* Deletes an item from the static acceleration array.
|
||||
*
|
||||
* @param string|int $key As given to get|set|delete
|
||||
* @return bool True on success, false otherwise.
|
||||
*/
|
||||
protected function delete_from_persist_cache($key) {
|
||||
unset($this->persistcache[$key]);
|
||||
if ($this->persistmaxsize !== false) {
|
||||
$dropkey = array_search($key, $this->persistkeys);
|
||||
unset($this->staticaccelerationarray[$key]);
|
||||
if ($this->staticaccelerationsize !== false) {
|
||||
$dropkey = array_search($key, $this->staticaccelerationkeys);
|
||||
if ($dropkey) {
|
||||
unset($this->persistkeys[$dropkey]);
|
||||
$this->persistcount--;
|
||||
unset($this->staticaccelerationkeys[$dropkey]);
|
||||
$this->staticaccelerationcount--;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -1459,9 +1464,8 @@ class cache_application extends cache implements cache_loader_with_locking {
|
||||
* This class is used for session caches returned by the cache::make methods.
|
||||
*
|
||||
* It differs from the application loader in a couple of noteable ways:
|
||||
* 1. Sessions are always expected to be persistent.
|
||||
* Because of this we don't ever use the persist cache and instead a session array
|
||||
* containing all of the data is maintained by this object.
|
||||
* 1. Sessions are always expected to exist.
|
||||
* Because of this we don't ever use the static acceleration array.
|
||||
* 2. Session data for a loader instance (store + definition) is consolidate into a
|
||||
* single array for storage within the store.
|
||||
* Along with this we embed a lastaccessed time with the data. This way we can
|
||||
@ -2074,7 +2078,7 @@ class cache_session extends cache {
|
||||
}
|
||||
|
||||
/**
|
||||
* The session loader never uses the persist cache.
|
||||
* The session loader never uses static acceleration.
|
||||
* Instead it stores things in the static $session variable. Shared between all session loaders.
|
||||
*
|
||||
* @return bool
|
||||
|
6
cache/disabledlib.php
vendored
6
cache/disabledlib.php
vendored
@ -49,8 +49,7 @@ class cache_disabled extends cache {
|
||||
* @param null $loader Unused.
|
||||
*/
|
||||
public function __construct(cache_definition $definition, cache_store $store, $loader = null) {
|
||||
$this->definition = $definition;
|
||||
$this->store = $store;
|
||||
// Nothing to do here.
|
||||
}
|
||||
|
||||
/**
|
||||
@ -228,7 +227,8 @@ class cache_factory_disabled extends cache_factory {
|
||||
* @param array $options An array of options, available options are:
|
||||
* - simplekeys : Set to true if the keys you will use are a-zA-Z0-9_
|
||||
* - simpledata : Set to true if the type of the data you are going to store is scalar, or an array of scalar vars
|
||||
* - persistent : If set to true the cache will persist construction requests.
|
||||
* - staticacceleration : If set to true the cache will hold onto all data passing through it.
|
||||
* - staticaccelerationsize : Sets the max size of the static acceleration array.
|
||||
* @return cache_application|cache_session|cache_request
|
||||
*/
|
||||
public function create_cache_from_params($mode, $component, $area, array $identifiers = array(), array $options = array()) {
|
||||
|
192
cache/tests/cache_test.php
vendored
192
cache/tests/cache_test.php
vendored
@ -149,8 +149,8 @@ class core_cache_testcase extends advanced_testcase {
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'component' => 'phpunit',
|
||||
'area' => 'test_default_application_cache',
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 1
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 1
|
||||
));
|
||||
$cache = cache::make('phpunit', 'test_default_application_cache');
|
||||
$this->assertInstanceOf('cache_application', $cache);
|
||||
@ -189,7 +189,7 @@ class core_cache_testcase extends advanced_testcase {
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'component' => 'phpunit',
|
||||
'area' => 'nostoretest2',
|
||||
'persistentdata' => true
|
||||
'staticacceleration' => true
|
||||
));
|
||||
$instance->phpunit_remove_stores();
|
||||
|
||||
@ -924,11 +924,11 @@ class core_cache_testcase extends advanced_testcase {
|
||||
'crazyevent'
|
||||
)
|
||||
));
|
||||
$instance->phpunit_add_definition('phpunit/eventpurgetestpersistentapp', array(
|
||||
$instance->phpunit_add_definition('phpunit/eventpurgetestaccelerated', array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'component' => 'phpunit',
|
||||
'area' => 'eventpurgetestpersistentapp',
|
||||
'persistentdata' => true,
|
||||
'area' => 'eventpurgetestaccelerated',
|
||||
'staticacceleration' => true,
|
||||
'invalidationevents' => array(
|
||||
'crazyevent'
|
||||
)
|
||||
@ -947,8 +947,8 @@ class core_cache_testcase extends advanced_testcase {
|
||||
$this->assertFalse($cache->get('testkey1'));
|
||||
$this->assertFalse($cache->get('testkey2'));
|
||||
|
||||
// Now test the persistent cache.
|
||||
$cache = cache::make('phpunit', 'eventpurgetestpersistentapp');
|
||||
// Now test the static acceleration array.
|
||||
$cache = cache::make('phpunit', 'eventpurgetestaccelerated');
|
||||
$this->assertTrue($cache->set('testkey1', 'test data 1'));
|
||||
$this->assertEquals('test data 1', $cache->get('testkey1'));
|
||||
$this->assertTrue($cache->set('testkey2', 'test data 2'));
|
||||
@ -975,11 +975,11 @@ class core_cache_testcase extends advanced_testcase {
|
||||
'crazyevent'
|
||||
)
|
||||
));
|
||||
$instance->phpunit_add_definition('phpunit/eventpurgetestpersistent', array(
|
||||
$instance->phpunit_add_definition('phpunit/eventpurgetestaccelerated', array(
|
||||
'mode' => cache_store::MODE_SESSION,
|
||||
'component' => 'phpunit',
|
||||
'area' => 'eventpurgetestpersistent',
|
||||
'persistentdata' => true,
|
||||
'area' => 'eventpurgetestaccelerated',
|
||||
'staticacceleration' => true,
|
||||
'invalidationevents' => array(
|
||||
'crazyevent'
|
||||
)
|
||||
@ -998,8 +998,8 @@ class core_cache_testcase extends advanced_testcase {
|
||||
$this->assertFalse($cache->get('testkey1'));
|
||||
$this->assertFalse($cache->get('testkey2'));
|
||||
|
||||
// Now test the persistent cache.
|
||||
$cache = cache::make('phpunit', 'eventpurgetestpersistent');
|
||||
// Now test the static acceleration array.
|
||||
$cache = cache::make('phpunit', 'eventpurgetestaccelerated');
|
||||
$this->assertTrue($cache->set('testkey1', 'test data 1'));
|
||||
$this->assertEquals('test data 1', $cache->get('testkey1'));
|
||||
$this->assertTrue($cache->set('testkey2', 'test data 2'));
|
||||
@ -1400,8 +1400,8 @@ class core_cache_testcase extends advanced_testcase {
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'component' => 'phpunit',
|
||||
'area' => 'test_application_locking',
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 1,
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 1,
|
||||
'requirelockingread' => true,
|
||||
'requirelockingwrite' => true
|
||||
));
|
||||
@ -1536,37 +1536,37 @@ class core_cache_testcase extends advanced_testcase {
|
||||
$this->assertArrayHasKey('cache_is_searchable', $cache->phpunit_get_store_implements());
|
||||
}
|
||||
|
||||
public function test_persistent_cache() {
|
||||
public function test_static_acceleration() {
|
||||
$instance = cache_config_phpunittest::instance();
|
||||
$instance->phpunit_add_definition('phpunit/persistentapp', array(
|
||||
$instance->phpunit_add_definition('phpunit/accelerated', array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'component' => 'phpunit',
|
||||
'area' => 'persistentapp',
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 3,
|
||||
'area' => 'accelerated',
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 3,
|
||||
));
|
||||
$instance->phpunit_add_definition('phpunit/persistentapp2', array(
|
||||
$instance->phpunit_add_definition('phpunit/accelerated2', array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'component' => 'phpunit',
|
||||
'area' => 'persistentapp2',
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 3,
|
||||
'area' => 'accelerated2',
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 3,
|
||||
));
|
||||
$instance->phpunit_add_definition('phpunit/persistentapp3', array(
|
||||
$instance->phpunit_add_definition('phpunit/accelerated3', array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'component' => 'phpunit',
|
||||
'area' => 'persistentapp3',
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 3,
|
||||
'area' => 'accelerated3',
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 3,
|
||||
));
|
||||
$instance->phpunit_add_definition('phpunit/persistentapp4', array(
|
||||
$instance->phpunit_add_definition('phpunit/accelerated4', array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'component' => 'phpunit',
|
||||
'area' => 'persistentapp3',
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 4,
|
||||
'area' => 'accelerated4',
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 4,
|
||||
));
|
||||
$cache = cache::make('phpunit', 'persistentapp');
|
||||
$cache = cache::make('phpunit', 'accelerated');
|
||||
$this->assertInstanceOf('cache_phpunit_application', $cache);
|
||||
|
||||
// Set and get three elements.
|
||||
@ -1576,112 +1576,112 @@ class core_cache_testcase extends advanced_testcase {
|
||||
$this->assertEquals('A', $cache->get('a'));
|
||||
$this->assertEquals(array('b' => 'B', 'c' => 'C'), $cache->get_many(array('b', 'c')));
|
||||
|
||||
// Make sure all items are in persistent cache.
|
||||
$this->assertEquals('A', $cache->phpunit_get_directly_from_persistcache('a'));
|
||||
$this->assertEquals('B', $cache->phpunit_get_directly_from_persistcache('b'));
|
||||
$this->assertEquals('C', $cache->phpunit_get_directly_from_persistcache('c'));
|
||||
// Make sure all items are in static acceleration array.
|
||||
$this->assertEquals('A', $cache->phpunit_get_directly_from_staticaccelerationarray('a'));
|
||||
$this->assertEquals('B', $cache->phpunit_get_directly_from_staticaccelerationarray('b'));
|
||||
$this->assertEquals('C', $cache->phpunit_get_directly_from_staticaccelerationarray('c'));
|
||||
|
||||
// Add new value and make sure it is in cache and it is in persistcache.
|
||||
// Add new value and make sure it is in cache and it is in array.
|
||||
$this->assertTrue($cache->set('d', 'D'));
|
||||
$this->assertEquals('D', $cache->phpunit_get_directly_from_persistcache('d'));
|
||||
$this->assertEquals('D', $cache->phpunit_get_directly_from_staticaccelerationarray('d'));
|
||||
$this->assertEquals('D', $cache->get('d'));
|
||||
|
||||
// Now the least recent accessed item (a) is no longer in persistent cache.
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('a'));
|
||||
$this->assertEquals('B', $cache->phpunit_get_directly_from_persistcache('b'));
|
||||
$this->assertEquals('C', $cache->phpunit_get_directly_from_persistcache('c'));
|
||||
// Now the least recent accessed item (a) is no longer in acceleration array.
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a'));
|
||||
$this->assertEquals('B', $cache->phpunit_get_directly_from_staticaccelerationarray('b'));
|
||||
$this->assertEquals('C', $cache->phpunit_get_directly_from_staticaccelerationarray('c'));
|
||||
|
||||
// Adding and deleting element.
|
||||
$this->assertTrue($cache->set('a', 'A'));
|
||||
$this->assertTrue($cache->delete('a'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('a'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a'));
|
||||
$this->assertFalse($cache->has('a'));
|
||||
|
||||
// Make sure "purge" deletes from persist as well.
|
||||
// Make sure "purge" deletes from the array as well.
|
||||
$cache->purge();
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('a'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('b'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('c'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('d'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('e'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('b'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('c'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('d'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('e'));
|
||||
|
||||
// Check that persistent cache holds the last accessed items by get/set.
|
||||
// Check that the array holds the last accessed items by get/set.
|
||||
$this->assertTrue($cache->set('a', 'A'));
|
||||
$this->assertTrue($cache->set('b', 'B'));
|
||||
$this->assertTrue($cache->set('c', 'C'));
|
||||
$this->assertTrue($cache->set('d', 'D'));
|
||||
$this->assertTrue($cache->set('e', 'E'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('a'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('b'));
|
||||
$this->assertEquals('C', $cache->phpunit_get_directly_from_persistcache('c'));
|
||||
$this->assertEquals('D', $cache->phpunit_get_directly_from_persistcache('d'));
|
||||
$this->assertEquals('E', $cache->phpunit_get_directly_from_persistcache('e'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('b'));
|
||||
$this->assertEquals('C', $cache->phpunit_get_directly_from_staticaccelerationarray('c'));
|
||||
$this->assertEquals('D', $cache->phpunit_get_directly_from_staticaccelerationarray('d'));
|
||||
$this->assertEquals('E', $cache->phpunit_get_directly_from_staticaccelerationarray('e'));
|
||||
|
||||
/** @var cache_phpunit_application $cache */
|
||||
$cache = cache::make('phpunit', 'persistentapp2');
|
||||
$cache = cache::make('phpunit', 'accelerated2');
|
||||
$this->assertInstanceOf('cache_phpunit_application', $cache);
|
||||
|
||||
// Check that persistent cache holds the last accessed items by get/set.
|
||||
// Check that the array holds the last accessed items by get/set.
|
||||
$this->assertTrue($cache->set('a', 'A'));
|
||||
$this->assertTrue($cache->set('b', 'B'));
|
||||
$this->assertTrue($cache->set('c', 'C'));
|
||||
$this->assertTrue($cache->set('d', 'D'));
|
||||
$this->assertTrue($cache->set('e', 'E'));
|
||||
// Current keys in persist cache: c, d, e.
|
||||
$this->assertEquals('C', $cache->phpunit_get_directly_from_persistcache('c'));
|
||||
$this->assertEquals('D', $cache->phpunit_get_directly_from_persistcache('d'));
|
||||
$this->assertEquals('E', $cache->phpunit_get_directly_from_persistcache('e'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('a'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('b'));
|
||||
// Current keys in the array: c, d, e.
|
||||
$this->assertEquals('C', $cache->phpunit_get_directly_from_staticaccelerationarray('c'));
|
||||
$this->assertEquals('D', $cache->phpunit_get_directly_from_staticaccelerationarray('d'));
|
||||
$this->assertEquals('E', $cache->phpunit_get_directly_from_staticaccelerationarray('e'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('b'));
|
||||
|
||||
$this->assertEquals('A', $cache->get('a'));
|
||||
// Current keys in persist cache: d, e, a.
|
||||
$this->assertEquals('D', $cache->phpunit_get_directly_from_persistcache('d'));
|
||||
$this->assertEquals('E', $cache->phpunit_get_directly_from_persistcache('e'));
|
||||
$this->assertEquals('A', $cache->phpunit_get_directly_from_persistcache('a'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('b'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('c'));
|
||||
// Current keys in the array: d, e, a.
|
||||
$this->assertEquals('D', $cache->phpunit_get_directly_from_staticaccelerationarray('d'));
|
||||
$this->assertEquals('E', $cache->phpunit_get_directly_from_staticaccelerationarray('e'));
|
||||
$this->assertEquals('A', $cache->phpunit_get_directly_from_staticaccelerationarray('a'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('b'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('c'));
|
||||
|
||||
// Current keys in persist cache: d, e, a.
|
||||
// Current keys in the array: d, e, a.
|
||||
$this->assertEquals(array('c' => 'C'), $cache->get_many(array('c')));
|
||||
// Current keys in persist cache: e, a, c.
|
||||
$this->assertEquals('E', $cache->phpunit_get_directly_from_persistcache('e'));
|
||||
$this->assertEquals('A', $cache->phpunit_get_directly_from_persistcache('a'));
|
||||
$this->assertEquals('C', $cache->phpunit_get_directly_from_persistcache('c'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('b'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('d'));
|
||||
// Current keys in the array: e, a, c.
|
||||
$this->assertEquals('E', $cache->phpunit_get_directly_from_staticaccelerationarray('e'));
|
||||
$this->assertEquals('A', $cache->phpunit_get_directly_from_staticaccelerationarray('a'));
|
||||
$this->assertEquals('C', $cache->phpunit_get_directly_from_staticaccelerationarray('c'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('b'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('d'));
|
||||
|
||||
|
||||
$cache = cache::make('phpunit', 'persistentapp3');
|
||||
$cache = cache::make('phpunit', 'accelerated3');
|
||||
$this->assertInstanceOf('cache_phpunit_application', $cache);
|
||||
|
||||
// Check that persistent cache holds the last accessed items by get/set.
|
||||
// Check that the array holds the last accessed items by get/set.
|
||||
$this->assertTrue($cache->set('a', 'A'));
|
||||
$this->assertTrue($cache->set('b', 'B'));
|
||||
$this->assertTrue($cache->set('c', 'C'));
|
||||
$this->assertTrue($cache->set('d', 'D'));
|
||||
$this->assertTrue($cache->set('e', 'E'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('a'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('b'));
|
||||
$this->assertEquals('C', $cache->phpunit_get_directly_from_persistcache('c'));
|
||||
$this->assertEquals('D', $cache->phpunit_get_directly_from_persistcache('d'));
|
||||
$this->assertEquals('E', $cache->phpunit_get_directly_from_persistcache('e'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('b'));
|
||||
$this->assertEquals('C', $cache->phpunit_get_directly_from_staticaccelerationarray('c'));
|
||||
$this->assertEquals('D', $cache->phpunit_get_directly_from_staticaccelerationarray('d'));
|
||||
$this->assertEquals('E', $cache->phpunit_get_directly_from_staticaccelerationarray('e'));
|
||||
|
||||
$this->assertTrue($cache->set('b', 'B2'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('a'));
|
||||
$this->assertEquals('B2', $cache->phpunit_get_directly_from_persistcache('b'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('c'));
|
||||
$this->assertEquals('D', $cache->phpunit_get_directly_from_persistcache('d'));
|
||||
$this->assertEquals('E', $cache->phpunit_get_directly_from_persistcache('e'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a'));
|
||||
$this->assertEquals('B2', $cache->phpunit_get_directly_from_staticaccelerationarray('b'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('c'));
|
||||
$this->assertEquals('D', $cache->phpunit_get_directly_from_staticaccelerationarray('d'));
|
||||
$this->assertEquals('E', $cache->phpunit_get_directly_from_staticaccelerationarray('e'));
|
||||
|
||||
$this->assertEquals(2, $cache->set_many(array('b' => 'B3', 'c' => 'C3')));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('a'));
|
||||
$this->assertEquals('B3', $cache->phpunit_get_directly_from_persistcache('b'));
|
||||
$this->assertEquals('C3', $cache->phpunit_get_directly_from_persistcache('c'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_persistcache('d'));
|
||||
$this->assertEquals('E', $cache->phpunit_get_directly_from_persistcache('e'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a'));
|
||||
$this->assertEquals('B3', $cache->phpunit_get_directly_from_staticaccelerationarray('b'));
|
||||
$this->assertEquals('C3', $cache->phpunit_get_directly_from_staticaccelerationarray('c'));
|
||||
$this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('d'));
|
||||
$this->assertEquals('E', $cache->phpunit_get_directly_from_staticaccelerationarray('e'));
|
||||
|
||||
$cache = cache::make('phpunit', 'persistentapp4');
|
||||
$cache = cache::make('phpunit', 'accelerated4');
|
||||
$this->assertInstanceOf('cache_phpunit_application', $cache);
|
||||
$this->assertTrue($cache->set('a', 'A'));
|
||||
$this->assertTrue($cache->set('a', 'A'));
|
||||
@ -1690,7 +1690,7 @@ class core_cache_testcase extends advanced_testcase {
|
||||
$this->assertTrue($cache->set('a', 'A'));
|
||||
$this->assertTrue($cache->set('a', 'A'));
|
||||
$this->assertTrue($cache->set('a', 'A'));
|
||||
$this->assertEquals('A', $cache->phpunit_get_directly_from_persistcache('a'));
|
||||
$this->assertEquals('A', $cache->phpunit_get_directly_from_staticaccelerationarray('a'));
|
||||
$this->assertEquals('A', $cache->get('a'));
|
||||
}
|
||||
}
|
||||
|
4
cache/tests/fixtures/lib.php
vendored
4
cache/tests/fixtures/lib.php
vendored
@ -253,12 +253,12 @@ class cache_phpunit_application extends cache_application {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given key directly from the persistdata cache.
|
||||
* Returns the given key directly from the static acceleration array.
|
||||
*
|
||||
* @param string $key
|
||||
* @return false|mixed
|
||||
*/
|
||||
public function phpunit_get_directly_from_persistcache($key) {
|
||||
public function phpunit_get_directly_from_staticaccelerationarray($key) {
|
||||
$key = $this->parse_key($key);
|
||||
return $this->get_from_persist_cache($key);
|
||||
}
|
||||
|
8
cache/upgrade.txt
vendored
8
cache/upgrade.txt
vendored
@ -1,6 +1,14 @@
|
||||
This files describes API changes in /cache/stores/* - cache store plugins.
|
||||
Information provided here is intended especially for developers.
|
||||
|
||||
=== 2.6 ===
|
||||
* All cache instances are recorded and subsequent requests are given a reference to the original instance.
|
||||
* The persistent option for the cache definition has been deprecated. Please use the staticacceleration option instead.
|
||||
* There is a new static acceleration option. If enabled data passing through the cache is held onto.
|
||||
* The persistentmaxsize option has been renamed to staticaccelerationsize. It does the same thing.
|
||||
* cache_definition::should_be_persistent has been deprecated. Please call cache_definition::use_static_acceleration instead.
|
||||
* cache_definition::get_persistent_max_size has been deprecated. Please call cache_definition::get_static_acceleration_size instead.
|
||||
|
||||
=== 2.5 ===
|
||||
* cleanup method renamed to instance_deleted.
|
||||
It is now called when the store is deleted as all comments suggested anyway.
|
||||
|
@ -36,8 +36,8 @@ $definitions = array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'simplekeys' => true,
|
||||
'simpledata' => true,
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 30
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 30
|
||||
),
|
||||
|
||||
// Used to store cache of all available translations.
|
||||
@ -58,8 +58,8 @@ $definitions = array(
|
||||
'requireidentifiers' => array(
|
||||
'dbfamily'
|
||||
),
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 15
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 15
|
||||
),
|
||||
|
||||
// Event invalidation cache.
|
||||
@ -71,7 +71,7 @@ $definitions = array(
|
||||
// cache will likely be used either lots or never.
|
||||
'eventinvalidation' => array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'persistentdata' => true,
|
||||
'staticacceleration' => true,
|
||||
'requiredataguarantee' => true,
|
||||
'simpledata' => true,
|
||||
),
|
||||
@ -103,7 +103,7 @@ $definitions = array(
|
||||
// Persistence is used because normally several settings within a script.
|
||||
'config' => array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'persistentdata' => true,
|
||||
'staticacceleration' => true,
|
||||
'simpledata' => true
|
||||
),
|
||||
|
||||
@ -114,7 +114,7 @@ $definitions = array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'simplekeys' => true, // The course id the groupings exist for.
|
||||
'simpledata' => true, // Array of stdClass objects containing only strings.
|
||||
'persistentdata' => true, // Likely there will be a couple of calls to this.
|
||||
'staticacceleration' => true, // Likely there will be a couple of calls to this.
|
||||
'persistmaxsize' => 2, // The original cache used 1, we've increased that to two.
|
||||
),
|
||||
|
||||
@ -123,7 +123,7 @@ $definitions = array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'simplekeys' => true,
|
||||
'simpledata' => true,
|
||||
'persistentdata' => true,
|
||||
'staticacceleration' => true,
|
||||
),
|
||||
|
||||
// YUI Module cache.
|
||||
@ -137,8 +137,8 @@ $definitions = array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'simplekeys' => true,
|
||||
'simpledata' => true,
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 2,
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 2,
|
||||
),
|
||||
|
||||
// Cache used by the {@link plugin_manager} class.
|
||||
@ -147,8 +147,8 @@ $definitions = array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'simplekeys' => true,
|
||||
'simpledata' => true,
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 2,
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 2,
|
||||
),
|
||||
|
||||
// Cache used by the {@link plugininfo_mod} class.
|
||||
@ -156,8 +156,8 @@ $definitions = array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'simplekeys' => true,
|
||||
'simpledata' => true,
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 1,
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 1,
|
||||
),
|
||||
|
||||
// Cache used by the {@link plugininfo_block} class.
|
||||
@ -165,8 +165,8 @@ $definitions = array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'simplekeys' => true,
|
||||
'simpledata' => true,
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 1,
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 1,
|
||||
),
|
||||
|
||||
// Cache used by the {@link plugininfo_filter} class.
|
||||
@ -174,8 +174,8 @@ $definitions = array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'simplekeys' => true,
|
||||
'simpledata' => true,
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 1,
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 1,
|
||||
),
|
||||
|
||||
// Cache used by the {@link plugininfo_repository} class.
|
||||
@ -183,8 +183,8 @@ $definitions = array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'simplekeys' => true,
|
||||
'simpledata' => true,
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 1,
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 1,
|
||||
),
|
||||
|
||||
// Cache used by the {@link plugininfo_portfolio} class.
|
||||
@ -192,15 +192,14 @@ $definitions = array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'simplekeys' => true,
|
||||
'simpledata' => true,
|
||||
'persistentdata' => true,
|
||||
'persistentmaxsize' => 1,
|
||||
>>>>>>> MDL-40903 cache: converted persistent into persistentdata
|
||||
'staticacceleration' => true,
|
||||
'staticaccelerationsize' => 1,
|
||||
),
|
||||
|
||||
// Used to store the full tree of course categories.
|
||||
'coursecattree' => array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'persistentdata' => true,
|
||||
'staticacceleration' => true,
|
||||
'invalidationevents' => array(
|
||||
'changesincoursecat',
|
||||
)
|
||||
@ -225,7 +224,7 @@ $definitions = array(
|
||||
// Cache course contacts for the courses.
|
||||
'coursecontacts' => array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'persistentdata' => true,
|
||||
'staticacceleration' => true,
|
||||
'simplekeys' => true,
|
||||
),
|
||||
// Used to store data for repositories to avoid repetitive DB queries within one request.
|
||||
|
Loading…
x
Reference in New Issue
Block a user