Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
cachestore_memcached Class Reference

The memcached store. More...

Inheritance diagram for cachestore_memcached:
cache_store cache_is_configurable cache_store_interface

Public Member Functions

 __construct ($name, array $configuration=array())
 Constructs the store instance. 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 ()
 Used to notify of configuration conflicts. More...
 
 initialise (cache_definition $definition)
 Initialises the cache. More...
 
 instance_created ()
 Performs any necessary operation when the store instance has been created. More...
 
 instance_deleted ()
 Performs any necessary clean up when the store instance is being deleted. More...
 
 is_connection_ready ()
 Confirm whether the connection is ready and usable. More...
 
 is_initialised ()
 Returns true once this instance has been initialised. More...
 
 is_ready ()
 Returns true if this store instance is ready to be used. More...
 
 is_searchable ()
 Returns true if the store instance is searchable. More...
 
 my_name ()
 Returns the name of this 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 false as this store does not support multiple identifiers. More...
 
 supports_native_ttl ()
 Returns true if the store instance supports native ttl. More...
 

Static Public Member Functions

static are_requirements_met ()
 Returns true 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 config_get_configuration_array ($data)
 Given the data from the add instance form this function creates a configuration array. More...
 
static config_get_hash_options ()
 Gets an array of hash options available during configuration. More...
 
static config_get_serialiser_options ()
 Gets an array of options to use as the serialiser. More...
 
static config_set_edit_form_data (moodleform $editform, array $config)
 Allows the cache store to set its data against the edit form before it is shown to the user. More...
 
static get_supported_features (array $configuration=array())
 Returns the supported features as a combined int. More...
 
static get_supported_modes (array $configuration=array())
 Returns the supported modes as a combined int. 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)
 Returns true if the given mode is supported by this store. 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 REQUIRED_VERSION = '2.0.0'
 The minimum required version of memcached in order to use this store.
 
const STATIC_ACCEL = '** static accel. **'
 Static caches.
 
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

 delete_many_connection (Memcached $connection, array $keys)
 Deletes several keys from the cache in a single action for a specific connection. More...
 

Static Protected Member Functions

static get_prefixed_keys (Memcached $connection, $prefix)
 Returns all of the keys in the given connection that belong to this cache store instance. More...
 

Protected Attributes

bool $candeletemulti = false
 True if Memcached::deleteMulti can be used, false otherwise. More...
 
bool $clustered = false
 Set to true when this store is clustered.
 
Memcached $connection
 The memcached connection.
 
cache_definition $definition
 The cache definition this store was initialised with.
 
bool $isinitialised = false
 Set to true when this store instance has been initialised.
 
bool $isready = false
 True when this instance is ready to be initialised.
 
bool $isshared = false
 True if the memcached server is shared, false otherwise. More...
 
store $name
 The name of the store.
 
array $options = array()
 The options used when establishing the connection.
 
string $prefix = ''
 The prefix to use on all keys.
 
array $servers = array()
 An array of servers to use during connection.
 
array $setconnections = array()
 The an array of memcache connections for the set servers, once established.
 
array $setservers = array()
 Array of servers to set when in clustered mode.
 

Detailed Description

The memcached store.

(Not to be confused with the memcache store)

Configuration options: servers: string: host:port:weight , ... compression: true, false serialiser: SERIALIZER_PHP, SERIALIZER_JSON, SERIALIZER_IGBINARY prefix: string: defaults to instance name hashmethod: HASH_DEFAULT, HASH_MD5, HASH_CRC, HASH_FNV1_64, HASH_FNV1A_64, HASH_FNV1_32, HASH_FNV1A_32, HASH_HSIEH, HASH_MURMUR bufferwrites: true, false

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

Constructor & Destructor Documentation

◆ __construct()

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

Constructs the store instance.

Noting that this function is not an initialisation. It is used to prepare the store for use. The store will be initialised when required and will be provided with a cache_definition at that time.

Parameters
string$name
array$configuration

Reimplemented from cache_store.

Member Function Documentation

◆ are_requirements_met()

static cachestore_memcached::are_requirements_met ( )
static

Returns true if the store requirements 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_dummy, cachestore_session, and cachestore_static.

◆ cleanup()

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

Reimplemented in cachestore_dummy.

◆ config_get_configuration_array()

static cachestore_memcached::config_get_configuration_array (   $data)
static

Given the data from the add instance form this function creates a configuration array.

Parameters
stdClass$data
Return values
array

Implements cache_is_configurable.

◆ config_get_hash_options()

static cachestore_memcached::config_get_hash_options ( )
static

Gets an array of hash options available during configuration.

Return values
array

◆ config_get_serialiser_options()

static cachestore_memcached::config_get_serialiser_options ( )
static

Gets an array of options to use as the serialiser.

Return values
array

◆ config_set_edit_form_data()

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

Allows the cache store to set its data against the edit form before it is shown to the user.

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_memcached::delete (   $key)

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 from cache_store.

◆ delete_many()

cachestore_memcached::delete_many ( array  $keys)

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 from cache_store.

◆ delete_many_connection()

cachestore_memcached::delete_many_connection ( Memcached  $connection,
array  $keys 
)
protected

Deletes several keys from the cache in a single action for a specific connection.

Parameters
Memcached$connectionThe connection to work on.
array$keysThe keys to delete
Return values
intThe number of items successfully deleted.

◆ get()

cachestore_memcached::get (   $key)

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 from cache_store.

◆ get_many()

cachestore_memcached::get_many (   $keys)

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 from cache_store.

◆ get_prefixed_keys()

static cachestore_memcached::get_prefixed_keys ( Memcached  $connection,
  $prefix 
)
staticprotected

Returns all of the keys in the given connection that belong to this cache store instance.

Requires php memcached extension version 2.0.0 or greater.

Parameters
Memcached$connection
string$prefix
Return values
array

◆ get_supported_features()

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

Returns the supported features as a combined int.

Parameters
array$configuration
Return values
int

Implements cache_store_interface.

◆ get_supported_modes()

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

Returns the supported modes as a combined int.

Parameters
array$configuration
Return values
int

Implements cache_store_interface.

◆ get_warnings()

cachestore_memcached::get_warnings ( )

Used to notify of configuration conflicts.

The warnings returned here will be displayed on the cache configuration screen.

Return values
string[]Returns an array of warnings (strings)

Reimplemented from cache_store.

◆ initialise()

cachestore_memcached::initialise ( cache_definition  $definition)

Initialises the cache.

Once this has been done the cache is all set to be used.

Exceptions
coding_exceptionif the instance has already been initialised.
Parameters
cache_definition$definition

Reimplemented from cache_store.

◆ initialise_test_instance()

static cachestore_memcached::initialise_test_instance ( cache_definition  $definition)
static

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

Parameters
cache_definition$definition
Return values
cachestore_memcached|false

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.

◆ instance_deleted()

cachestore_memcached::instance_deleted ( )

Performs any necessary clean up when the store instance is being deleted.

Reimplemented from cache_store.

◆ is_connection_ready()

cachestore_memcached::is_connection_ready ( )

Confirm whether the connection is ready and usable.

Return values
boolean

◆ is_initialised()

cachestore_memcached::is_initialised ( )

Returns true once this instance has been initialised.

Return values
bool

Reimplemented from cache_store.

◆ is_ready()

cachestore_memcached::is_ready ( )

Returns true if this store instance is ready to be used.

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_memcached::is_supported_mode (   $mode)
static

Returns true if the given mode is supported by this store.

Parameters
int$modeOne of cache_store::MODE_*
Return values
bool

Implements cache_store_interface.

◆ my_name()

cachestore_memcached::my_name ( )

Returns the name of this instance.

Return values
string

Reimplemented from cache_store.

◆ purge()

cachestore_memcached::purge ( )

Purges the cache deleting all items within it.

Return values
booleanTrue on success. False otherwise.

Reimplemented from cache_store.

◆ ready_to_be_used_for_testing()

static cachestore_memcached::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 from cache_store.

◆ set()

cachestore_memcached::set (   $key,
  $data 
)

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 from cache_store.

◆ set_many()

cachestore_memcached::set_many ( array  $keyvaluearray)

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

cachestore_memcached::supports_multiple_identifiers ( )

Returns false as this store does not support multiple identifiers.

(This optional function is a performance optimisation; it must be consistent with the value from get_supported_features.)

Return values
boolFalse

Reimplemented from cache_store.

◆ 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_memcached::unit_test_configuration ( )
static

Generates the appropriate configuration required for unit testing.

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

Implements cache_store_interface.

Member Data Documentation

◆ $candeletemulti

bool cachestore_memcached::$candeletemulti = false
protected

True if Memcached::deleteMulti can be used, false otherwise.

This required extension version 2.0.0 or greater.

◆ $isshared

bool cachestore_memcached::$isshared = false
protected

True if the memcached server is shared, false otherwise.

This required extension version 2.0.0 or greater.

◆ 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: