|
| __construct (cache_definition $definition, cache_store $store, $loader=null) |
| Overrides the cache construct method.
|
|
| __clone () |
| Fixes the instance up after a clone.
|
|
| acquire_lock ($key) |
| Acquires a lock on the given key.
|
|
| check_lock_state ($key) |
| Checks if this cache has a lock on the given key.
|
|
| delete ($key, $recurse=true) |
| Delete the given key from the cache.
|
|
| delete_many (array $keys, $recurse=true) |
| Delete all of the given keys from the cache.
|
|
| get ($key, $strictness=IGNORE_MISSING) |
| Retrieves the value for the given key from the cache.
|
|
| get_identifier () |
| Returns the identifier to use.
|
|
| get_many (array $keys, $strictness=IGNORE_MISSING) |
| Retrieves an array of values for an array of keys.
|
|
| get_versioned ($key, int $requiredversion, int $strictness=IGNORE_MISSING, &$actualversion=null) |
| Retrieves the value and actual version for the given key, with at least the required version.
|
|
| has ($key, $tryloadifpossible=false) |
| Test is a cache has a key.
|
|
| has ($key) |
| Test is a cache has a key.
|
|
| has_all (array $keys) |
| Test is a cache has all of the given keys.
|
|
| has_any (array $keys) |
| Test if a cache has at least one of the given keys.
|
|
| purge () |
| Purges the cache store, and loader if there is one.
|
|
| purge_current_user () |
| Subclasses may support purging cache of all data belonging to the current user.
|
|
| release_lock ($key) |
| Releases the lock this cache has on the given key.
|
|
| set ($key, $data) |
| Sends a key => value pair to the cache.
|
|
| set_identifiers (array $identifiers) |
| Alters the identifiers that have been provided to the definition.
|
|
| set_many (array $keyvaluearray) |
| Sends several key => value pairs to the cache.
|
|
| set_versioned ($key, int $version, $data) |
| Sets the value for the given key with the given version.
|
|
|
static | compare_purge_tokens ($tokena, $tokenb) |
| Compare a pair of purge tokens.
|
|
static | get_purge_token ($reset=false) |
| Get a 'purge' token used for cache invalidation handling.
|
|
static | make ($component, $area, array $identifiers=array(), $unused=null) |
| Creates a new cache instance for a pre-defined definition.
|
|
static | make_from_params ($mode, $component, $area, array $identifiers=array(), array $options=array()) |
| Creates a new cache instance based upon the given params.
|
|
static | now ($float=false) |
| Returns the timestamp from the first request for the time from the cache API.
|
|
|
| deep_clone ($value) |
| Creates a reference free clone of the given value.
|
|
| delete_from_persist_cache () |
|
| ensure_cachelock_available () |
| Ensure that the dedicated lock store is ready to go.
|
|
| get_datasource () |
| Returns the data source associated with this cache.
|
|
| get_definition () |
| Returns the cache definition.
|
|
| get_from_persist_cache () |
|
| get_implementation ($key, int $requiredversion, int $strictness, &$actualversion=null) |
| Retrieves the value for the given key from the cache.
|
|
| get_loader () |
| Returns the loader associated with this instance.
|
|
| get_store () |
| Returns the cache store.
|
|
| handle_invalidation_events () |
| Process any outstanding invalidation events for the cache we are registering,.
|
|
| has_a_ttl () |
| Returns true if the cache is making use of a ttl.
|
|
| is_in_persist_cache () |
|
| is_using_persist_cache () |
|
| parse_key ($key) |
| Parses the key turning it into a string (or array is required) suitable to be passed to the cache store.
|
|
| requires_serialisation ($value, $depth=1) |
| Checks to see if a var requires serialisation.
|
|
| set_data_source (cache_data_source $datasource) |
| Set the data source for this cache.
|
|
| set_implementation ($key, int $version, $data, bool $setparents=true) |
| Sends a key => value pair to the cache.
|
|
| set_in_persist_cache () |
|
| set_is_sub_loader ($setting=true) |
| Used to inform the loader of its state as a sub loader, or as the top of the chain.
|
|
| set_loader (cache_loader $loader) |
| Set the loader for this cache.
|
|
| static_acceleration_delete ($key) |
| Deletes an item from the static acceleration array.
|
|
| static_acceleration_get ($key) |
| Returns the item from the static acceleration array if it exists there.
|
|
| static_acceleration_has ($key) |
| Returns true if the requested key exists within the static acceleration array.
|
|
| static_acceleration_purge () |
| Purge the static acceleration cache.
|
|
| static_acceleration_set ($key, $data) |
| Sets a key value pair into the static acceleration array.
|
|
| store_supports_key_awareness () |
| Returns true if the store supports key awareness.
|
|
| store_supports_native_locking () |
| Returns true if the store natively supports locking.
|
|
| store_supports_native_ttl () |
| Returns true if the cache store supports native ttl.
|
|
| unref ($data) |
| Removes references where required.
|
|
| use_static_acceleration () |
| Returns true if this cache is making use of the static acceleration array.
|
|
|
cache_lock_interface | $cachelockinstance |
| Gets set to a cache_store to use for locking if the caches primary store doesn't support locking natively.
|
|
string | $lockidentifier |
| Lock identifier.
|
|
array | $locks |
| Store a list of locks acquired by this process.
|
|
cache_store | $nativelocking = null |
| Gets set to true if the cache's primary store natively supports locking.
|
|
bool | $perfdebug = false |
| Gets set to true if we want to collect performance information about the cache API.
|
|
bool | $requirelocking = false |
| Gets set to true if the cache is going to be using locking.
|
|
bool | $requirelockingbeforewrite = false |
| Gets set to true if the cache writes (set|delete) must have a manual lock created first.
|
|
strubg | $storetype = 'unknown' |
| Gets set to the class name of the store during initialisation.
|
|
bool | $subloader = false |
| Determines if this loader is a sub loader, not the top of the chain.
|
|
An application cache.
This class is used for application caches returned by the cache\make methods. On top of the standard functionality it also allows locking to be required and or manually operated.
This cache class should never be interacted with directly. Instead you should always use the cache\make methods. It is technically possible to call those methods through this class however there is no guarantee that you will get an instance of this class back again.
static cache::compare_purge_tokens |
( |
| $tokena, |
|
|
| $tokenb ) |
|
staticinherited |
Compare a pair of purge tokens.
If the two tokens are identical, then the return value is 0. If the time component of token A is newer than token B, then a positive value is returned. If the time component of token B is newer than token A, then a negative value is returned.
Note: This function is intended for use from within the Cache API only and not by plugins, or cache stores.
- Parameters
-
string | $tokena | |
string | $tokenb | |
- Return values
-
Retrieves an array of values for an array of keys.
Using this function comes with potential performance implications. Not all cache stores will support get_many/set_many operations and in order to replicate this functionality will call the equivalent singular method for each item provided. This should not deter you from using this function as there is a performance benefit in situations where the cache store does support it, but you should be aware of this fact.
- Parameters
-
array | $keys | The keys of the data being requested. Each key can be any structure although using a scalar string or int is recommended in the interests of performance. In advanced cases an array may be useful such as in situations requiring the multi-key functionality. |
int | $strictness | One of IGNORE_MISSING or MUST_EXIST. |
- Return values
-
array | An array of key value pairs for the items that could be retrieved from the cache. If MUST_EXIST was used and not all keys existed within the cache then an exception will be thrown. Otherwise any key that did not exist will have a data value of false within the results. |
- Exceptions
-
Implements cache_loader.
Reimplemented in cache_disabled, and cache_session.
cache::get_versioned |
( |
| $key, |
|
|
int | $requiredversion, |
|
|
int | $strictness = IGNORE_MISSING, |
|
|
& | $actualversion = null ) |
|
inherited |
Retrieves the value and actual version for the given key, with at least the required version.
If there is no value for the key, or there is a value but it doesn't have the required version, then this function will return null (or throw an exception if you set strictness to MUST_EXIST).
This function can be used to make it easier to support localisable caches (where the cache could be stored on a local server as well as a shared cache). Specifying the version means that it will automatically retrieve the correct version if available, either from the local server or [if that has an older version] from the shared server.
If the cached version is newer than specified version, it will be returned regardless. For example, if you request version 4, but the locally cached version is 5, it will be returned. If you request version 6, and the locally cached version is 5, then the system will look in higher-level caches (if any); if there still isn't a version 6 or greater, it will return null.
You must use this function if you use set_versioned.
- Parameters
-
string | int | $key | The key for the data being requested. |
int | $requiredversion | Minimum required version of the data |
int | $strictness | One of IGNORE_MISSING or MUST_EXIST. |
mixed | $actualversion | If specified, will be set to the actual version number retrieved |
- Return values
-
mixed | Data from the cache, or false if the key did not exist or was too old |
- Exceptions
-
Implements cache_loader.
cache::has |
( |
| $key, |
|
|
| $tryloadifpossible = false ) |
|
inherited |
Test is a cache has a key.
The use of the has methods is strongly discouraged. In a high load environment the cache may well change between the test and any subsequent action (get, set, delete etc). Instead it is recommended to write your code in such a way they it performs the following steps:
-
Attempt to retrieve the information.
-
Generate the information.
-
Attempt to set the information
Its also worth mentioning that not all stores support key tests. For stores that don't support key tests this functionality is mimicked by using the equivalent get method. Just one more reason you should not use these methods unless you have a very good reason to do so.
- Parameters
-
string | int | $key | |
bool | $tryloadifpossible | If set to true, the cache doesn't contain the key, and there is another cache loader or data source then the code will try load the key value from the next item in the chain. |
- Return values
-
bool | True if the cache has the requested key, false otherwise. |
Reimplemented in cache_disabled, and cache_session.
cache_loader::has |
( |
| $key | ) |
|
|
inherited |
Test is a cache has a key.
The use of the has methods is strongly discouraged. In a high load environment the cache may well change between the test and any subsequent action (get, set, delete etc). Instead it is recommended to write your code in such a way they it performs the following steps:
-
Attempt to retrieve the information.
-
Generate the information.
-
Attempt to set the information
Its also worth mentioning that not all stores support key tests. For stores that don't support key tests this functionality is mimicked by using the equivalent get method. Just one more reason you should not use these methods unless you have a very good reason to do so.
- Parameters
-
- Return values
-
bool | True if the cache has the requested key, false otherwise. |
cache::has_all |
( |
array | $keys | ) |
|
|
inherited |
Test is a cache has all of the given keys.
It is strongly recommended to avoid the use of this function if not absolutely required. In a high load environment the cache may well change between the test and any subsequent action (get, set, delete etc).
Its also worth mentioning that not all stores support key tests. For stores that don't support key tests this functionality is mimicked by using the equivalent get method. Just one more reason you should not use these methods unless you have a very good reason to do so.
- Parameters
-
- Return values
-
bool | True if the cache has all of the given keys, false otherwise. |
Implements cache_loader.
Reimplemented in cache_disabled, and cache_session.
cache::has_any |
( |
array | $keys | ) |
|
|
inherited |
Test if a cache has at least one of the given keys.
It is strongly recommended to avoid the use of this function if not absolutely required. In a high load environment the cache may well change between the test and any subsequent action (get, set, delete etc).
Its also worth mentioning that not all stores support key tests. For stores that don't support key tests this functionality is mimicked by using the equivalent get method. Just one more reason you should not use these methods unless you have a very good reason to do so.
- Parameters
-
- Return values
-
bool | True if the cache has at least one of the given keys |
Implements cache_loader.
Reimplemented in cache_disabled, and cache_session.
cache::set |
( |
| $key, |
|
|
| $data ) |
|
inherited |
Sends a key => value pair to the cache.
// This code will add four entries to the cache, one for each url. $cache->set('main', 'http://moodle.org'); $cache->set('docs', 'http://docs.moodle.org'); $cache->set('tracker', 'http://tracker.moodle.org'); $cache->set('qa', 'http://qa.moodle.net');
- Parameters
-
string | int | $key | The key for the data being requested. It can be any structure although using a scalar string or int is recommended in the interests of performance. In advanced cases an array may be useful such as in situations requiring the multi-key functionality. |
mixed | $data | The data to set against the key. |
- Return values
-
bool | True on success, false otherwise. |
Implements cache_loader.
Reimplemented in cache_session.
cache_application::set_implementation |
( |
| $key, |
|
|
int | $version, |
|
|
| $data, |
|
|
bool | $setparents = true ) |
|
protected |
Sends a key => value pair to the cache.
// This code will add four entries to the cache, one for each url. $cache->set('main', 'http://moodle.org'); $cache->set('docs', 'http://docs.moodle.org'); $cache->set('tracker', 'http://tracker.moodle.org'); $cache->set('qa', 'http://qa.moodle.net');
- Parameters
-
string | int | $key | The key for the data being requested. |
int | $version | Version number |
mixed | $data | The data to set against the key. |
bool | $setparents | If true, sets all parent loaders, otherwise only this one |
- Return values
-
bool | True on success, false otherwise. |
- Exceptions
-
Reimplemented from cache.
cache_application::set_many |
( |
array | $keyvaluearray | ) |
|
Sends several key => value pairs to the cache.
Using this function comes with potential performance implications. Not all cache stores will support get_many/set_many operations and in order to replicate this functionality will call the equivalent singular method for each item provided. This should not deter you from using this function as there is a performance benefit in situations where the cache store does support it, but you should be aware of this fact.
// This code will add four entries to the cache, one for each url. $cache->set_many(array( 'main' => 'http://moodle.org', 'docs' => 'http://docs.moodle.org', 'tracker' => 'http://tracker.moodle.org', 'qa' => ''http://qa.moodle.net' ));
- Parameters
-
array | $keyvaluearray | An array of key => value pairs to send to the cache. |
- Return values
-
int | The number of items successfully set. It is up to the developer to check this matches the number of items. ... if they care that is. |
- Exceptions
-
Reimplemented from cache.
cache::set_versioned |
( |
| $key, |
|
|
int | $version, |
|
|
| $data ) |
|
inherited |
Sets the value for the given key with the given version.
The cache does not store multiple versions - any existing version will be overwritten with this one. This function should only be used if there is a known 'current version' (e.g. stored in a database table). It only ensures that the cache does not return outdated data.
This function can be used to help implement localisable caches (where the cache could be stored on a local server as well as a shared cache). The version will be recorded alongside the item and get_versioned will always return the correct version.
The version number must be an integer that always increases. This could be based on the current time, or a stored value that increases by 1 each time it changes, etc.
If you use this function you must use get_versioned to retrieve the data.
- Parameters
-
string | int | $key | The key for the data being set. |
int | $version | Integer for the version of the data |
mixed | $data | The data to set against the key. |
- Return values
-
bool | True on success, false otherwise. |
Implements cache_loader.