Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

The library file for the memcached cache store. This file is part of the memcached cache store, it contains the API for interacting with an instance of the store.

Copyright: 2012 Sam Hemelryk
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 853 lines (30 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 1 class


Class: cachestore_memcached  - X-Ref

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

__construct($name, array $configuration = array()   X-Ref
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.

param: string $name
param: array $configuration

is_connection_ready()   X-Ref
Confirm whether the connection is ready and usable.

return: boolean

initialise(cache_definition $definition)   X-Ref
Initialises the cache.

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

param: cache_definition $definition

is_initialised()   X-Ref
Returns true once this instance has been initialised.

return: bool

is_ready()   X-Ref
Returns true if this store instance is ready to be used.

return: bool

are_requirements_met()   X-Ref
Returns true if the store requirements are met.

return: bool

is_supported_mode($mode)   X-Ref
Returns true if the given mode is supported by this store.

param: int $mode One of cache_store::MODE_*
return: bool

get_supported_features(array $configuration = array()   X-Ref
Returns the supported features as a combined int.

param: array $configuration
return: int

supports_multiple_identifiers()   X-Ref
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: bool False

get_supported_modes(array $configuration = array()   X-Ref
Returns the supported modes as a combined int.

param: array $configuration
return: int

get($key)   X-Ref
Retrieves an item from the cache store given its key.

param: string $key The key to retrieve
return: mixed The data that was associated with the key, or false if the key did not exist.

get_many($keys)   X-Ref
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.

param: array $keys The array of keys to retrieve
return: array An array of items from the cache. There will be an item for each key, those that were not in the store will

set($key, $data)   X-Ref
Sets an item in the cache given its key and data value.

param: string $key The key to use.
param: mixed $data The data to set.
return: bool True if the operation was a success false otherwise.

set_many(array $keyvaluearray)   X-Ref
Sets many items in the cache in a single transaction.

param: array $keyvaluearray An array of key value pairs. Each item in the array will be an associative array with two
return: int The number of items successfully set. It is up to the developer to check this matches the number of items

delete($key)   X-Ref
Deletes an item from the cache store.

param: string $key The key to delete.
return: bool Returns true if the operation was a success, false otherwise.

delete_many(array $keys)   X-Ref
Deletes several keys from the cache in a single action.

param: array $keys The keys to delete
return: int The number of items successfully deleted.

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

param: Memcached $connection The connection to work on.
param: array $keys The keys to delete
return: int The number of items successfully deleted.

purge()   X-Ref
Purges the cache deleting all items within it.

return: boolean True on success. False otherwise.

get_prefixed_keys(Memcached $connection, $prefix)   X-Ref
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.

param: Memcached $connection
param: string $prefix
return: array

config_get_serialiser_options()   X-Ref
Gets an array of options to use as the serialiser.

return: array

config_get_hash_options()   X-Ref
Gets an array of hash options available during configuration.

return: array

config_get_configuration_array($data)   X-Ref
Given the data from the add instance form this function creates a configuration array.

param: stdClass $data
return: array

config_set_edit_form_data(moodleform $editform, array $config)   X-Ref
Allows the cache store to set its data against the edit form before it is shown to the user.

param: moodleform $editform
param: array $config

instance_deleted()   X-Ref
Performs any necessary clean up when the store instance is being deleted.


initialise_test_instance(cache_definition $definition)   X-Ref
Generates an instance of the cache store that can be used for testing.

param: cache_definition $definition
return: cachestore_memcached|false

unit_test_configuration()   X-Ref
Generates the appropriate configuration required for unit testing.

return: array Array of unit test configuration data to be used by initialise().

my_name()   X-Ref
Returns the name of this instance.

return: string

get_warnings()   X-Ref
Used to notify of configuration conflicts.

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

return: string[] Returns an array of warnings (strings)

ready_to_be_used_for_testing()   X-Ref
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: bool