Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
cache_store Class Reference
Inheritance diagram for cache_store:
cache_store_interface cachestore_apcu cachestore_dummy cachestore_file cachestore_memcached cachestore_mongodb cachestore_redis session_data_store static_data_store

Public Member Functions

 __construct ($name, array $configuration=array())
 Constructs an instance of the cache store. More...
 
 cleanup ()
 
 create_clone (array $details=array())
 Creates a clone of this store instance ready to be initialised. More...
 
 delete ($key)
 Deletes an item from the cache store. More...
 
 delete_many (array $keys)
 Deletes several keys from the cache in a single action. More...
 
 get ($key)
 Retrieves an item from the cache store given its key. More...
 
 get_many ($keys)
 Retrieves several items from the cache store in a single transaction. More...
 
 get_warnings ()
 Can be overridden to return any warnings this store instance should make to the admin. More...
 
 initialise (cache_definition $definition)
 Initialises a new instance of the cache store given the definition the instance is to be used for. More...
 
 instance_created ()
 Performs any necessary operation when the store instance has been created. More...
 
 instance_deleted ()
 Performs any necessary operation when the store instance is being deleted. More...
 
 is_initialised ()
 Returns true if this cache store instance has been initialised. More...
 
 is_ready ()
 Returns true if this cache store instance is ready to use. More...
 
 is_searchable ()
 Returns true if the store instance is searchable. More...
 
 my_name ()
 Returns the name of this store instance. More...
 
 purge ()
 Purges the cache deleting all items within it. More...
 
 set ($key, $data)
 Sets an item in the cache given its key and data value. More...
 
 set_many (array $keyvaluearray)
 Sets many items in the cache in a single transaction. 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 ()
 Static method to check if the store requirements are met. More...
 
static can_add_instance ()
 Returns true if the user can add an instance of the store plugin. More...
 
static get_supported_features (array $configuration=array())
 Returns the supported features as a binary flag. More...
 
static get_supported_modes (array $configuration=array())
 Returns the supported modes as a binary flag. More...
 
static initialise_test_instance (cache_definition $definition)
 Generates an instance of the cache store that can be used for testing. More...
 
static is_supported_mode ($mode)
 Static method to check if a store is usable with the 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 ()
 Generates the appropriate configuration required for unit testing. More...
 

Public Attributes

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.
 

Constructor & Destructor Documentation

◆ __construct()

cache_store::__construct (   $name,
array  $configuration = array() 
)
abstract

Constructs an instance of the cache store.

The constructor should be responsible for creating anything needed by the store that is not specific to a definition. Tasks such as opening a connection to check it is available are best done here. Tasks that are definition specific such as creating a storage area for the definition data or creating key tables and indexs are best done within the initialise method.

Once a store has been constructed the cache API will check it is ready to be intialised with a definition by called $this->is_ready(). If the setup of the store failed (connection could not be established for example) then that method should return false so that the store instance is not selected for use.

Parameters
string$nameThe name of the cache store
array$configurationThe configuration for this store instance.

Reimplemented in cachestore_dummy, cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, and cachestore_apcu.

Member Function Documentation

◆ are_requirements_met()

static cache_store_interface::are_requirements_met ( )
staticinherited

Static method to check if the store requirements are met.

Return values
boolTrue if the stores software/hardware requirements have been met and it can be used. False otherwise.

Implemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ can_add_instance()

static cache_store::can_add_instance ( )
static

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.

◆ cleanup()

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

Reimplemented in cachestore_dummy.

◆ create_clone()

cache_store::create_clone ( array  $details = array())

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()

cache_store::delete (   $key)
abstract

Deletes an item from the cache store.

Parameters
string$keyThe key to delete.
Return values
boolReturns true if the operation was a success, false otherwise.

Reimplemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ delete_many()

cache_store::delete_many ( array  $keys)
abstract

Deletes several keys from the cache in a single action.

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

Reimplemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ get()

cache_store::get (   $key)
abstract

Retrieves an item from the cache store given its key.

Parameters
string$keyThe key to retrieve
Return values
mixedThe data that was associated with the key, or false if the key did not exist.

Reimplemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ get_many()

cache_store::get_many (   $keys)
abstract

Retrieves several items from the cache store in a single transaction.

If not all of the items are available in the cache then the data value for those that are missing will be set to false.

Parameters
array$keysThe array of keys to retrieve
Return values
arrayAn array of items from the cache. There will be an item for each key, those that were not in the store will be set to false.

Reimplemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ get_supported_features()

static cache_store_interface::get_supported_features ( array  $configuration = array())
staticinherited

Returns the supported features as a binary flag.

Parameters
array$configurationThe configuration of a store to consider specifically.
Return values
intThe supported features.

Implemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ get_supported_modes()

static cache_store_interface::get_supported_modes ( array  $configuration = array())
staticinherited

Returns the supported modes as a binary flag.

Parameters
array$configurationThe configuration of a store to consider specifically.
Return values
intThe supported modes.

Implemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ get_warnings()

cache_store::get_warnings ( )

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.

◆ initialise()

cache_store::initialise ( cache_definition  $definition)
abstract

Initialises a new instance of the cache store given the definition the instance is to be used for.

This function should be used to run any definition specific setup the store instance requires. Tasks such as creating storage areas, or creating indexes are best done here.

Its important to note that the initialise method is expected to always succeed. If there are setup tasks that may fail they should be done within the __construct method and should they fail is_ready should return false.

Parameters
cache_definition$definition

Reimplemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ initialise_test_instance()

static cache_store_interface::initialise_test_instance ( cache_definition  $definition)
staticinherited

Generates an instance of the cache store that can be used for testing.

Returns an instance of the cache store, or false if one cannot be created.

Parameters
cache_definition$definition
Return values
cache_store|false

Implemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ instance_created()

cache_store::instance_created ( )

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

Since
Moodle 2.5

Reimplemented in cachestore_file.

◆ instance_deleted()

cache_store::instance_deleted ( )

Performs any necessary operation when the store instance is being deleted.

This method may be called before the store has been initialised.

Since
Moodle 2.5
See also
cleanup()

Reimplemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ is_initialised()

cache_store::is_initialised ( )
abstract

Returns true if this cache store instance has been initialised.

Return values
bool

Reimplemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ is_ready()

cache_store::is_ready ( )

Returns true if this cache store instance is ready to use.

Return values
bool

Reimplemented in cachestore_redis, cachestore_mongodb, cachestore_memcached, and cachestore_file.

◆ is_searchable()

cache_store::is_searchable ( )

Returns true if the store instance is searchable.

Return values
bool

◆ is_supported_mode()

static cache_store_interface::is_supported_mode (   $mode)
staticinherited

Static method to check if a store is usable with the given mode.

Parameters
int$modeOne of cache_store::MODE_*

Implemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ my_name()

cache_store::my_name ( )
abstract

Returns the name of this store instance.

Return values
string

Reimplemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ purge()

cache_store::purge ( )
abstract

Purges the cache deleting all items within it.

Return values
booleanTrue on success. False otherwise.

Reimplemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ ready_to_be_used_for_testing()

static cache_store::ready_to_be_used_for_testing ( )
static

Returns true if this cache store instance is both suitable for testing, and ready for testing.

Cache stores that support being used as the default store for unit and acceptance testing should override this function and return true if there requirements have been met.

Return values
bool

Reimplemented in cachestore_redis, cachestore_mongodb, cachestore_memcached, and cachestore_apcu.

◆ set()

cache_store::set (   $key,
  $data 
)
abstract

Sets an item in the cache given its key and data value.

Parameters
string$keyThe key to use.
mixed$dataThe data to set.
Return values
boolTrue if the operation was a success false otherwise.

Reimplemented in cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ set_many()

cache_store::set_many ( array  $keyvaluearray)
abstract

Sets many items in the cache in a single transaction.

Parameters
array$keyvaluearrayAn array of key value pairs. Each item in the array will be an associative array with two keys, 'key' and 'value'.
Return values
intThe number of items successfully set. It is up to the developer to check this matches the number of items sent ... if they care that is.

Reimplemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

◆ supports_data_guarantee()

cache_store::supports_data_guarantee ( )

Returns true if the store instance guarantees data.

Return values
bool

◆ supports_dereferencing_objects()

cache_store::supports_dereferencing_objects ( )

Returns true if the store automatically dereferences objects.

Return values
bool

◆ supports_multiple_identifiers()

cache_store::supports_multiple_identifiers ( )

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 ( )

Returns true if the store instance supports native ttl.

Return values
bool

◆ unit_test_configuration()

static cache_store_interface::unit_test_configuration ( )
staticinherited

Generates the appropriate configuration required for unit testing.

Return values
arrayArray of unit test configuration data to be used by initialise().

Implemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.

Member Data Documentation

◆ DEREFERENCES_OBJECTS

const cache_store::DEREFERENCES_OBJECTS = 16

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

Application caches.

These are shared caches.

◆ MODE_REQUEST

const cache_store::MODE_REQUEST = 4

Request caches.

Static caches really.

◆ MODE_SESSION

const cache_store::MODE_SESSION = 2

Session caches.

Just access to the PHP session.


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