Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
Redis Cache Store. More...
Public Member Functions | |
__construct ($name, array $configuration=array()) | |
Constructs an instance of this type of store. More... | |
acquire_lock ($key, $ownerid) | |
Tries to acquire a lock with a given name. More... | |
check_lock_state ($key, $ownerid) | |
Checks a lock with a given name and owner information. More... | |
cleanup () | |
create_clone (array $details=array()) | |
Creates a clone of this store instance ready to be initialised. More... | |
delete ($key) | |
Delete the given key. More... | |
delete_many (array $keys) | |
Delete many keys. More... | |
find_all () | |
Finds all of the keys being used by this cache store instance. More... | |
find_by_prefix ($prefix) | |
Finds all of the keys whose keys start with the given prefix. More... | |
get ($key) | |
Get the value associated with a given key. More... | |
get_many ($keys) | |
Get the values associated with a list of keys. More... | |
get_warnings () | |
Can be overridden to return any warnings this store instance should make to the admin. More... | |
has ($key) | |
Determines if the store has a given key. More... | |
has_all (array $keys) | |
Determines if the store has all of the keys in a list. More... | |
has_any (array $keys) | |
Determines if the store has any of the keys in a list. More... | |
initialise (cache_definition $definition) | |
Initialize the store. More... | |
instance_created () | |
Performs any necessary operation when the store instance has been created. More... | |
instance_deleted () | |
Cleans up after an instance of the store. | |
is_initialised () | |
Determine if the store is initialized. More... | |
is_ready () | |
Determine if the store is ready for use. More... | |
is_searchable () | |
Returns true if the store instance is searchable. More... | |
my_name () | |
Get the name of the store. More... | |
purge () | |
Purges all keys from the store. More... | |
release_lock ($key, $ownerid) | |
Releases a given lock if the owner information matches. More... | |
set ($key, $value) | |
Set the value of a key. More... | |
set_many (array $keyvaluearray) | |
Set the values of many keys. More... | |
supports_data_guarantee () | |
Returns true if the store instance guarantees data. More... | |
supports_dereferencing_objects () | |
Returns true if the store automatically dereferences objects. More... | |
supports_multiple_identifiers () | |
Returns true if the store instance supports multiple identifiers. More... | |
supports_native_ttl () | |
Returns true if the store instance supports native ttl. More... | |
Static Public Member Functions | |
static | are_requirements_met () |
Determines if the requirements for this type of store are met. More... | |
static | can_add_instance () |
Returns true if the user can add an instance of the store plugin. More... | |
static | config_get_compressor_options () |
Gets an array of options to use as the compressor. More... | |
static | config_get_configuration_array ($data) |
Creates a configuration array from given 'add instance' form data. More... | |
static | config_get_serializer_options () |
Gets an array of options to use as the serialiser. More... | |
static | config_set_edit_form_data (moodleform $editform, array $config) |
Sets form data from a configuration array. More... | |
static | get_supported_features (array $configuration=array()) |
Get the features of this type of cache store. More... | |
static | get_supported_modes (array $configuration=array()) |
Get the supported modes of this type of cache store. More... | |
static | initialise_test_instance (cache_definition $definition) |
Creates an instance of the store for testing. More... | |
static | is_supported_mode ($mode) |
Determines if this type of store supports a given mode. More... | |
static | ready_to_be_used_for_testing () |
Returns true if this cache store instance is both suitable for testing, and ready for testing. More... | |
static | unit_test_configuration () |
Return configuration to use when unit testing. More... | |
Public Attributes | |
const | COMPRESSOR_NONE = 0 |
Compressor: none. | |
const | COMPRESSOR_PHP_GZIP = 1 |
Compressor: PHP GZip. | |
const | COMPRESSOR_PHP_ZSTD = 2 |
Compressor: PHP Zstandard. | |
const | DEREFERENCES_OBJECTS = 16 |
The cache store dereferences objects. More... | |
const | IS_SEARCHABLE = 8 |
The cache is searchable by key. | |
const | MODE_APPLICATION = 1 |
Application caches. More... | |
const | MODE_REQUEST = 4 |
Request caches. More... | |
const | MODE_SESSION = 2 |
Session caches. More... | |
const | SUPPORTS_DATA_GUARANTEE = 2 |
Ensures data remains in the cache once set. | |
const | SUPPORTS_MULTIPLE_IDENTIFIERS = 1 |
Supports multi-part keys. | |
const | SUPPORTS_NATIVE_TTL = 4 |
Supports a native ttl system. | |
Protected Member Functions | |
new_redis ($server, $prefix='', $password='') | |
Create a new Redis instance and connect to the server. More... | |
ping (Redis $redis) | |
See if we can ping Redis server. More... | |
Protected Attributes | |
int | $compressor = self::COMPRESSOR_NONE |
Compressor for this store. | |
cache_definition | $definition = null |
Cache definition for this store. | |
string | $hash |
The definition hash, used for hash key. | |
boolean | $isready = false |
Flag for readiness! | |
string | $name |
Name of this store. | |
Redis | $redis |
Connection to Redis for this store. | |
int | $serializer = Redis::SERIALIZER_PHP |
Serializer for this store. | |
Redis Cache Store.
To allow separation of definitions in Moodle and faster purging, each cache is implemented as a Redis hash. That is a trade-off between having functionality of TTL and being able to manage many caches in a single redis instance. Given the recommendation not to use TTL if at all possible and the benefits of having many stores in Redis using the hash configuration, the hash implementation has been used.
cachestore_redis::__construct | ( | $name, | |
array | $configuration = array() |
||
) |
Constructs an instance of this type of store.
string | $name | |
array | $configuration |
Reimplemented from cache_store.
cachestore_redis::acquire_lock | ( | $key, | |
$ownerid | |||
) |
Tries to acquire a lock with a given name.
string | $key | Name of the lock to acquire. |
string | $ownerid | Information to identify owner of lock if acquired. |
bool | True if the lock was acquired, false if it was not. |
Implements cache_is_lockable.
|
static |
Determines if the requirements for this type of store are met.
bool |
Implements cache_store_interface.
|
staticinherited |
Returns true if the user can add an instance of the store plugin.
bool |
Reimplemented in cachestore_static, cachestore_session, and cachestore_dummy.
cachestore_redis::check_lock_state | ( | $key, | |
$ownerid | |||
) |
Checks a lock with a given name and owner information.
string | $key | Name of the lock to check. |
string | $ownerid | Owner information to check existing lock against. |
mixed | True if the lock exists and the owner information matches, null if the lock does not exist, and false otherwise. |
Implements cache_is_lockable.
|
inherited |
|
static |
Gets an array of options to use as the compressor.
array |
|
static |
Creates a configuration array from given 'add instance' form data.
stdClass | $data |
array |
Implements cache_is_configurable.
|
static |
Gets an array of options to use as the serialiser.
array |
|
static |
Sets form data from a configuration array.
moodleform | $editform | |
array | $config |
Implements cache_is_configurable.
|
inherited |
Creates a clone of this store instance ready to be initialised.
This method is used so that a cache store needs only be constructed once. Future requests for an instance of the store will be given a cloned instance.
If you are writing a cache store that isn't compatible with the clone operation you can override this method to handle any situations you want before cloning.
array | $details | An array containing the details of the store from the cache config. |
cache_store |
cachestore_redis::delete | ( | $key | ) |
Delete the given key.
string | $key | The key to delete. |
bool | True if the delete operation succeeds, false otherwise. |
Reimplemented from cache_store.
cachestore_redis::delete_many | ( | array | $keys | ) |
Delete many keys.
array | $keys | The keys to delete. |
int | The number of keys successfully deleted. |
Reimplemented from cache_store.
cachestore_redis::find_all | ( | ) |
Finds all of the keys being used by this cache store instance.
array | of all keys in the hash as a numbered array. |
Implements cache_is_searchable.
cachestore_redis::find_by_prefix | ( | $prefix | ) |
Finds all of the keys whose keys start with the given prefix.
string | $prefix |
array | List of keys that match this prefix. |
Implements cache_is_searchable.
cachestore_redis::get | ( | $key | ) |
Get the value associated with a given key.
string | $key | The key to get the value of. |
mixed | The value of the key, or false if there is no value associated with the key. |
Reimplemented from cache_store.
cachestore_redis::get_many | ( | $keys | ) |
Get the values associated with a list of keys.
array | $keys | The keys to get the values of. |
array | An array of the values of the given keys. |
Reimplemented from cache_store.
|
static |
Get the features of this type of cache store.
array | $configuration |
int |
Implements cache_store_interface.
|
static |
Get the supported modes of this type of cache store.
array | $configuration |
int |
Implements cache_store_interface.
|
inherited |
Can be overridden to return any warnings this store instance should make to the admin.
This should be used to notify things like configuration conflicts etc. The warnings returned here will be displayed on the cache configuration screen.
string[] | An array of warning strings from the store instance. |
Reimplemented in cachestore_memcached.
cachestore_redis::has | ( | $key | ) |
Determines if the store has a given key.
string | $key | The key to check for. |
bool | True if the key exists, false if it does not. |
Implements cache_is_key_aware.
cachestore_redis::has_all | ( | array | $keys | ) |
Determines if the store has all of the keys in a list.
array | $keys | The keys to check for. |
bool | True if all of the keys are found, false otherwise. |
Implements cache_is_key_aware.
cachestore_redis::has_any | ( | array | $keys | ) |
Determines if the store has any of the keys in a list.
array | $keys | The keys to check for. |
bool | True if any of the keys are found, false none of the keys are found. |
Implements cache_is_key_aware.
cachestore_redis::initialise | ( | cache_definition | $definition | ) |
Initialize the store.
cache_definition | $definition |
bool |
Reimplemented from cache_store.
|
static |
Creates an instance of the store for testing.
cache_definition | $definition |
mixed | An instance of the store, or false if an instance cannot be created. |
Implements cache_store_interface.
|
inherited |
Performs any necessary operation when the store instance has been created.
Reimplemented in cachestore_file.
cachestore_redis::is_initialised | ( | ) |
cachestore_redis::is_ready | ( | ) |
|
inherited |
Returns true if the store instance is searchable.
bool |
|
static |
Determines if this type of store supports a given mode.
int | $mode |
bool |
Implements cache_store_interface.
cachestore_redis::my_name | ( | ) |
|
protected |
Create a new Redis instance and connect to the server.
string | $server | The server connection string |
string | $prefix | The key prefix |
string | $password | The server connection password |
Redis |
|
protected |
See if we can ping Redis server.
Redis | $redis |
bool |
cachestore_redis::purge | ( | ) |
|
static |
Returns true if this cache store instance is both suitable for testing, and ready for testing.
When TEST_CACHESTORE_REDIS_TESTSERVERS is set, then we are ready to be use d for testing.
bool |
Reimplemented from cache_store.
cachestore_redis::release_lock | ( | $key, | |
$ownerid | |||
) |
Releases a given lock if the owner information matches.
string | $key | Name of the lock to release. |
string | $ownerid | Owner information to use. |
bool | True if the lock is released, false if it is not. |
Implements cache_is_lockable.
cachestore_redis::set | ( | $key, | |
$value | |||
) |
Set the value of a key.
string | $key | The key to set the value of. |
mixed | $value | The value. |
bool | True if the operation succeeded, false otherwise. |
Reimplemented from cache_store.
cachestore_redis::set_many | ( | array | $keyvaluearray | ) |
Set the values of many keys.
array | $keyvaluearray | An array of key/value pairs. Each item in the array is an associative array with two keys, 'key' and 'value'. |
int | The number of key/value pairs successfuly set. |
Reimplemented from cache_store.
|
inherited |
Returns true if the store instance guarantees data.
bool |
|
inherited |
Returns true if the store automatically dereferences objects.
bool |
|
inherited |
Returns true if the store instance supports multiple identifiers.
bool |
Reimplemented in cachestore_static, cachestore_session, cachestore_mongodb, cachestore_memcached, and cachestore_file.
|
inherited |
Returns true if the store instance supports native ttl.
bool |
|
static |
Return configuration to use when unit testing.
array |
Implements cache_store_interface.
|
inherited |
The cache store dereferences objects.
When set, loaders will assume that all data coming from this store has already had all references resolved. So even for complex object structures it will not try to remove references again.
|
inherited |
Application caches.
These are shared caches.
|
inherited |
Request caches.
Static caches really.
|
inherited |
Session caches.
Just access to the PHP session.