Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
cachestore_redis Class Reference

Redis Cache Store. More...

Inheritance diagram for cachestore_redis:
cache_store cache_is_key_aware cache_is_lockable cache_is_configurable cache_is_searchable cache_store_interface

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.
 

Detailed Description

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.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

cachestore_redis::__construct (   $name,
array  $configuration = array() 
)

Constructs an instance of this type of store.

Parameters
string$name
array$configuration

Reimplemented from cache_store.

Member Function Documentation

◆ acquire_lock()

cachestore_redis::acquire_lock (   $key,
  $ownerid 
)

Tries to acquire a lock with a given name.

See also
cache_is_lockable
Parameters
string$keyName of the lock to acquire.
string$owneridInformation to identify owner of lock if acquired.
Return values
boolTrue if the lock was acquired, false if it was not.

Implements cache_is_lockable.

◆ are_requirements_met()

static cachestore_redis::are_requirements_met ( )
static

Determines if the requirements for this type of store are met.

Return values
bool

Implements cache_store_interface.

◆ can_add_instance()

static cache_store::can_add_instance ( )
staticinherited

Returns true if the user can add an instance of the store plugin.

Return values
bool

Reimplemented in cachestore_static, cachestore_session, and cachestore_dummy.

◆ check_lock_state()

cachestore_redis::check_lock_state (   $key,
  $ownerid 
)

Checks a lock with a given name and owner information.

See also
cache_is_lockable
Parameters
string$keyName of the lock to check.
string$owneridOwner information to check existing lock against.
Return values
mixedTrue if the lock exists and the owner information matches, null if the lock does not exist, and false otherwise.

Implements cache_is_lockable.

◆ cleanup()

cache_store::cleanup ( )
inherited
Deprecated:
since 2.5
See also
cache_store::instance_deleted()

Reimplemented in cachestore_dummy.

◆ config_get_compressor_options()

static cachestore_redis::config_get_compressor_options ( )
static

Gets an array of options to use as the compressor.

Return values
array

◆ config_get_configuration_array()

static cachestore_redis::config_get_configuration_array (   $data)
static

Creates a configuration array from given 'add instance' form data.

See also
cache_is_configurable
Parameters
stdClass$data
Return values
array

Implements cache_is_configurable.

◆ config_get_serializer_options()

static cachestore_redis::config_get_serializer_options ( )
static

Gets an array of options to use as the serialiser.

Return values
array

◆ config_set_edit_form_data()

static cachestore_redis::config_set_edit_form_data ( moodleform  $editform,
array  $config 
)
static

Sets form data from a configuration array.

See also
cache_is_configurable
Parameters
moodleform$editform
array$config

Implements cache_is_configurable.

◆ create_clone()

cache_store::create_clone ( array  $details = array())
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.

Parameters
array$detailsAn array containing the details of the store from the cache config.
Return values
cache_store

◆ delete()

cachestore_redis::delete (   $key)

Delete the given key.

Parameters
string$keyThe key to delete.
Return values
boolTrue if the delete operation succeeds, false otherwise.

Reimplemented from cache_store.

◆ delete_many()

cachestore_redis::delete_many ( array  $keys)

Delete many keys.

Parameters
array$keysThe keys to delete.
Return values
intThe number of keys successfully deleted.

Reimplemented from cache_store.

◆ find_all()

cachestore_redis::find_all ( )

Finds all of the keys being used by this cache store instance.

Return values
arrayof all keys in the hash as a numbered array.

Implements cache_is_searchable.

◆ find_by_prefix()

cachestore_redis::find_by_prefix (   $prefix)

Finds all of the keys whose keys start with the given prefix.

Parameters
string$prefix
Return values
arrayList of keys that match this prefix.

Implements cache_is_searchable.

◆ get()

cachestore_redis::get (   $key)

Get the value associated with a given key.

Parameters
string$keyThe key to get the value of.
Return values
mixedThe value of the key, or false if there is no value associated with the key.

Reimplemented from cache_store.

◆ get_many()

cachestore_redis::get_many (   $keys)

Get the values associated with a list of keys.

Parameters
array$keysThe keys to get the values of.
Return values
arrayAn array of the values of the given keys.

Reimplemented from cache_store.

◆ get_supported_features()

static cachestore_redis::get_supported_features ( array  $configuration = array())
static

Get the features of this type of cache store.

Parameters
array$configuration
Return values
int

Implements cache_store_interface.

◆ get_supported_modes()

static cachestore_redis::get_supported_modes ( array  $configuration = array())
static

Get the supported modes of this type of cache store.

Parameters
array$configuration
Return values
int

Implements cache_store_interface.

◆ get_warnings()

cache_store::get_warnings ( )
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.

Return values
string[]An array of warning strings from the store instance.

Reimplemented in cachestore_memcached.

◆ has()

cachestore_redis::has (   $key)

Determines if the store has a given key.

See also
cache_is_key_aware
Parameters
string$keyThe key to check for.
Return values
boolTrue if the key exists, false if it does not.

Implements cache_is_key_aware.

◆ has_all()

cachestore_redis::has_all ( array  $keys)

Determines if the store has all of the keys in a list.

See also
cache_is_key_aware
Parameters
array$keysThe keys to check for.
Return values
boolTrue if all of the keys are found, false otherwise.

Implements cache_is_key_aware.

◆ has_any()

cachestore_redis::has_any ( array  $keys)

Determines if the store has any of the keys in a list.

See also
cache_is_key_aware
Parameters
array$keysThe keys to check for.
Return values
boolTrue if any of the keys are found, false none of the keys are found.

Implements cache_is_key_aware.

◆ initialise()

cachestore_redis::initialise ( cache_definition  $definition)

Initialize the store.

Parameters
cache_definition$definition
Return values
bool

Reimplemented from cache_store.

◆ initialise_test_instance()

static cachestore_redis::initialise_test_instance ( cache_definition  $definition)
static

Creates an instance of the store for testing.

Parameters
cache_definition$definition
Return values
mixedAn instance of the store, or false if an instance cannot be created.

Implements cache_store_interface.

◆ instance_created()

cache_store::instance_created ( )
inherited

Performs any necessary operation when the store instance has been created.

Since
Moodle 2.5

Reimplemented in cachestore_file.

◆ is_initialised()

cachestore_redis::is_initialised ( )

Determine if the store is initialized.

Return values
bool

Reimplemented from cache_store.

◆ is_ready()

cachestore_redis::is_ready ( )

Determine if the store is ready for use.

Return values
bool

Reimplemented from cache_store.

◆ is_searchable()

cache_store::is_searchable ( )
inherited

Returns true if the store instance is searchable.

Return values
bool

◆ is_supported_mode()

static cachestore_redis::is_supported_mode (   $mode)
static

Determines if this type of store supports a given mode.

Parameters
int$mode
Return values
bool

Implements cache_store_interface.

◆ my_name()

cachestore_redis::my_name ( )

Get the name of the store.

Return values
string

Reimplemented from cache_store.

◆ new_redis()

cachestore_redis::new_redis (   $server,
  $prefix = '',
  $password = '' 
)
protected

Create a new Redis instance and connect to the server.

Parameters
string$serverThe server connection string
string$prefixThe key prefix
string$passwordThe server connection password
Return values
Redis

◆ ping()

cachestore_redis::ping ( Redis  $redis)
protected

See if we can ping Redis server.

Parameters
Redis$redis
Return values
bool

◆ purge()

cachestore_redis::purge ( )

Purges all keys from the store.

Return values
bool

Reimplemented from cache_store.

◆ ready_to_be_used_for_testing()

static cachestore_redis::ready_to_be_used_for_testing ( )
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.

Return values
bool

Reimplemented from cache_store.

◆ release_lock()

cachestore_redis::release_lock (   $key,
  $ownerid 
)

Releases a given lock if the owner information matches.

See also
cache_is_lockable
Parameters
string$keyName of the lock to release.
string$owneridOwner information to use.
Return values
boolTrue if the lock is released, false if it is not.

Implements cache_is_lockable.

◆ set()

cachestore_redis::set (   $key,
  $value 
)

Set the value of a key.

Parameters
string$keyThe key to set the value of.
mixed$valueThe value.
Return values
boolTrue if the operation succeeded, false otherwise.

Reimplemented from cache_store.

◆ set_many()

cachestore_redis::set_many ( array  $keyvaluearray)

Set the values of many keys.

Parameters
array$keyvaluearrayAn array of key/value pairs. Each item in the array is an associative array with two keys, 'key' and 'value'.
Return values
intThe number of key/value pairs successfuly set.

Reimplemented from cache_store.

◆ supports_data_guarantee()

cache_store::supports_data_guarantee ( )
inherited

Returns true if the store instance guarantees data.

Return values
bool

◆ supports_dereferencing_objects()

cache_store::supports_dereferencing_objects ( )
inherited

Returns true if the store automatically dereferences objects.

Return values
bool

◆ supports_multiple_identifiers()

cache_store::supports_multiple_identifiers ( )
inherited

Returns true if the store instance supports multiple identifiers.

Return values
bool

Reimplemented in cachestore_static, cachestore_session, cachestore_mongodb, cachestore_memcached, and cachestore_file.

◆ supports_native_ttl()

cache_store::supports_native_ttl ( )
inherited

Returns true if the store instance supports native ttl.

Return values
bool

◆ unit_test_configuration()

static cachestore_redis::unit_test_configuration ( )
static

Return configuration to use when unit testing.

Return values
array

Implements cache_store_interface.

Member Data Documentation

◆ DEREFERENCES_OBJECTS

const cache_store::DEREFERENCES_OBJECTS = 16
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.

◆ MODE_APPLICATION

const cache_store::MODE_APPLICATION = 1
inherited

Application caches.

These are shared caches.

◆ MODE_REQUEST

const cache_store::MODE_REQUEST = 4
inherited

Request caches.

Static caches really.

◆ MODE_SESSION

const cache_store::MODE_SESSION = 2
inherited

Session caches.

Just access to the PHP session.


The documentation for this class was generated from the following file: