Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
|
Required as it is needed for cache_config_disabled which extends cache_config_writer. More...
Public Member Functions | |
__construct (cache_definition $definition, cache_store $store, $loader=null) | |
Constructs the cache. | |
acquire_lock ($key) | |
Pretend that we got a lock to avoid errors. | |
check_lock_state ($key) | |
Pretend that we have a lock to avoid errors. | |
delete ($key, $recurse=true) | |
Deletes an item from the cache. | |
delete_many (array $keys, $recurse=true) | |
Deletes many items at once from the cache. | |
get ($key, $strictness=IGNORE_MISSING) | |
Retrieves the value for the given key from the cache. | |
get_many (array $keys, $strictness=IGNORE_MISSING) | |
Gets many keys at once from the cache. | |
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) | |
Checks if the cache has the requested key. | |
has ($key) | |
Test is a cache has a key. | |
has_all (array $keys) | |
Checks if the cache has all of the requested keys. | |
has_any (array $keys) | |
Checks if the cache has any of the requested keys. | |
purge () | |
Purges all items from the cache. | |
purge_current_user () | |
Subclasses may support purging cache of all data belonging to the current user. | |
release_lock ($key) | |
Pretend that we released a lock to avoid errors. | |
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) | |
Sets many key value pairs in the cache at once. | |
set_versioned ($key, int $version, $data) | |
Sets the value for the given key with the given version. | |
Static Public Member Functions | |
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. | |
Public Attributes | |
int const | VERSION_NONE = -1 |
Constant for cache entries that do not have a version number. | |
Protected Member Functions | |
deep_clone ($value) | |
Creates a reference free clone of the given value. | |
delete_from_persist_cache () | |
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) | |
Gets a 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) | |
Sets a key value pair in 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. | |
Static Protected Member Functions | |
static | check_version ($result, int $requiredversion) |
Checks returned data to see if it matches the specified version number. | |
Protected Attributes | |
cache_store null | $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 | $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. | |
Static Protected Attributes | |
static int | $now |
We need a timestamp to use within the cache API. | |
static string | $purgetoken |
A purge token used to distinguish between multiple cache purges in the same second. | |
Required as it is needed for cache_config_disabled which extends cache_config_writer.
The cache loader class used when the Cache has been disabled.
cache_disabled::__construct | ( | cache_definition | $definition, |
cache_store | $store, | ||
$loader = null ) |
Constructs the cache.
cache_definition | $definition | |
cache_store | $store | |
null | $loader | Unused. |
Reimplemented from cache.
cache_disabled::acquire_lock | ( | $key | ) |
Pretend that we got a lock to avoid errors.
int | string | $key |
bool |
Implements cache_loader_with_locking.
cache_disabled::check_lock_state | ( | $key | ) |
Pretend that we have a lock to avoid errors.
int | string | $key |
bool |
Implements cache_loader_with_locking.
|
staticprotectedinherited |
Checks returned data to see if it matches the specified version number.
For versioned data, this returns the version_wrapper object (or false). For other data, it returns the actual data (or false).
mixed | $result | Result data |
int | $requiredversion | Required version number or VERSION_NONE if there must be no version |
bool | True if version is current, false if not (or if result is false) |
coding_exception | If unexpected type of data (versioned vs non-versioned) is found |
|
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.
string | $tokena | |
string | $tokenb |
int |
|
protectedinherited |
Creates a reference free clone of the given value.
mixed | $value |
mixed |
cache_disabled::delete | ( | $key, | |
$recurse = true ) |
Deletes an item from the cache.
int | string | $key | Unused. |
bool | $recurse | Unused. |
bool |
Reimplemented from cache.
|
protectedinherited |
cache_disabled::delete_many | ( | array | $keys, |
$recurse = true ) |
Deletes many items at once from the cache.
array | $keys | Unused. |
bool | $recurse | Unused. |
int |
Reimplemented from cache.
|
inherited |
Retrieves the value for the given key from the cache.
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. |
int | $strictness | One of IGNORE_MISSING | MUST_EXIST |
mixed|false | The data from the cache or false if the key did not exist within the cache. |
coding_exception |
Implements cache_loader.
|
protectedinherited |
Returns the data source associated with this cache.
cache_data_source|false |
|
protectedinherited |
Returns the cache definition.
cache_definition |
|
protectedinherited |
|
protected |
Gets a key from the cache.
int | string | $key | |
int | $requiredversion | Minimum required version of the data or cache\VERSION_NONE |
int | $strictness | Unused. |
mixed | &$actualversion | If specified, will be set to the actual version number retrieved |
bool |
Reimplemented from cache.
|
protectedinherited |
cache_disabled::get_many | ( | array | $keys, |
$strictness = IGNORE_MISSING ) |
Gets many keys at once from the cache.
array | $keys | |
int | $strictness | Unused. |
array |
Reimplemented from cache.
|
staticinherited |
Get a 'purge' token used for cache invalidation handling.
Note: This function is intended for use from within the Cache API only and not by plugins, or cache stores.
bool | $reset | Whether to reset the token and generate a new one. |
string |
|
protectedinherited |
Returns the cache store.
cache_store |
|
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.
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 |
mixed | Data from the cache, or false if the key did not exist or was too old |
coding_exception | If you call get_versioned on a non-versioned cache key |
Implements cache_loader.
|
protectedinherited |
Process any outstanding invalidation events for the cache we are registering,.
Identifiers and event invalidation are not compatible with each other at this time. As a result the cache does not need to consider identifiers when working out what to invalidate.
cache_disabled::has | ( | $key, | |
$tryloadifpossible = false ) |
Checks if the cache has the requested key.
int | string | $key | Unused. |
bool | $tryloadifpossible | Unused. |
bool |
Reimplemented from cache.
|
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:
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.
string | int | $key |
bool | True if the cache has the requested key, false otherwise. |
|
protectedinherited |
Returns true if the cache is making use of a ttl.
bool |
cache_disabled::has_all | ( | array | $keys | ) |
Checks if the cache has all of the requested keys.
array | $keys | Unused. |
bool |
Reimplemented from cache.
cache_disabled::has_any | ( | array | $keys | ) |
Checks if the cache has any of the requested keys.
array | $keys | Unused. |
bool |
Reimplemented from cache.
|
protectedinherited |
|
protectedinherited |
|
staticinherited |
Creates a new cache instance for a pre-defined definition.
string | $component | The component for the definition |
string | $area | The area for the definition |
array | $identifiers | Any additional identifiers that should be provided to the definition. |
string | $unused | Used to be datasourceaggregate but that was removed and this is now unused. |
cache_application|cache_session|cache_store |
|
staticinherited |
Creates a new cache instance based upon the given params.
int | $mode | One of cache_store\MODE_* |
string | $component | The component this cache relates to. |
string | $area | The area this cache relates to. |
array | $identifiers | Any additional identifiers that should be provided to the definition. |
array | $options | An array of options, available options are:
|
cache_application|cache_session|cache_request |
|
staticinherited |
Returns the timestamp from the first request for the time from the cache API.
This stamp needs to be used for all ttl and time based operations to ensure that we don't end up with timing issues.
bool | $float | Whether to use floating precision accuracy. |
int|float |
|
protectedinherited |
Parses the key turning it into a string (or array is required) suitable to be passed to the cache store.
string | int | $key | As passed to get|set|delete etc. |
string|array | String unless the store supports multi-identifiers in which case an array if returned. |
Reimplemented in cache_session.
cache_disabled::purge | ( | ) |
|
inherited |
Subclasses may support purging cache of all data belonging to the current user.
Reimplemented in cache_session.
cache_disabled::release_lock | ( | $key | ) |
Pretend that we released a lock to avoid errors.
int | string | $key |
bool |
Implements cache_loader_with_locking.
|
protectedinherited |
Checks to see if a var requires serialisation.
mixed | $value | The value to check. |
int | $depth | Used to ensure we don't enter an endless loop (think recursion). |
bool | Returns true if the value is going to require serialisation in order to ensure a reference free copy or false if its safe to clone. |
|
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');
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. |
bool | True on success, false otherwise. |
Implements cache_loader.
Reimplemented in cache_session.
|
protectedinherited |
Set the data source for this cache.
cache_data_source | $datasource |
|
inherited |
Alters the identifiers that have been provided to the definition.
This is an advanced method and should not be used unless really needed. It allows the developer to slightly alter the definition without having to re-establish the cache. It will cause more processing as the definition will need to clear and reprepare some of its properties.
array | $identifiers |
|
protected |
Sets a key value pair in the cache.
int | string | $key | Unused. |
int | $version | Unused. |
mixed | $data | Unused. |
bool | $setparents | Unused. |
bool |
Reimplemented from cache.
|
protectedinherited |
|
protectedinherited |
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 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.
bool | $setting |
|
protectedinherited |
Set the loader for this cache.
cache_loader | $loader |
cache_disabled::set_many | ( | array | $keyvaluearray | ) |
Sets many key value pairs in the cache at once.
array | $keyvaluearray | Unused. |
int |
Reimplemented from cache.
|
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.
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. |
bool | True on success, false otherwise. |
Implements cache_loader.
|
protectedinherited |
Deletes an item from the static acceleration array.
string | int | $key | As given to get|set|delete |
bool | True on success, false otherwise. |
|
protectedinherited |
Returns the item from the static acceleration array if it exists there.
string | $key | The parsed key |
mixed|false | Dereferenced data from the static acceleration array or false if it wasn't there. |
|
protectedinherited |
Returns true if the requested key exists within the static acceleration array.
string | $key | The parsed key |
bool |
|
protectedinherited |
Sets a key value pair into the static acceleration array.
string | $key | The parsed key |
mixed | $data |
bool |
|
protectedinherited |
Returns true if the store supports key awareness.
bool |
|
protectedinherited |
Returns true if the store natively supports locking.
bool |
|
protectedinherited |
Returns true if the cache store supports native ttl.
bool |
|
protectedinherited |
Removes references where required.
stdClass | array | $data |
mixed | What ever was put in but without any references. |
|
protectedinherited |
Returns true if this cache is making use of the static acceleration array.
bool |
Reimplemented in cache_session.
|
protectedinherited |
Gets set to true if the cache's primary store natively supports locking.
If it does then we use that, otherwise we need to instantiate a second store to use for locking.
|
staticprotectedinherited |
We need a timestamp to use within the cache API.
This stamp needs to be used for all ttl and time based operations to ensure that we don't end up with timing issues.
|
staticprotectedinherited |
A purge token used to distinguish between multiple cache purges in the same second.
This is in the format <microtime>-<random string>.
|
protectedinherited |
Gets set to the class name of the store during initialisation.
This is used several times in the cache class internally and having it here helps speed up processing.