Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

Cache store - base class This file is part of Moodle's cache API, affectionately called MUC. It contains the components that are required in order to use caching.

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

Defines 2 classes


Interface: cache_store_interface  - X-Ref

Cache store interface.

This interface defines the static methods that must be implemented by every cache store plugin.
To ensure plugins implement this class the abstract cache_store class implements this interface.

are_requirements_met()   X-Ref
Static method to check if the store requirements are met.

return: bool True if the stores software/hardware requirements have been met and it can be used. False otherwise.

is_supported_mode($mode)   X-Ref
Static method to check if a store is usable with the given mode.

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

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

param: array $configuration The configuration of a store to consider specifically.
return: int The supported features.

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

param: array $configuration The configuration of a store to consider specifically.
return: int The supported modes.

initialise_test_instance(cache_definition $definition)   X-Ref
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.

param: cache_definition $definition
return: cache_store|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().

Class: cache_store  - X-Ref

Abstract cache store class.

All cache store plugins must extend this base class.
It lays down the foundation for what is required of a cache store plugin.

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

return: bool

cleanup()   X-Ref


instance_created()   X-Ref
Performs any necessary operation when the store instance has been created.


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

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


can_add_instance()   X-Ref
Returns true if the user can add an instance of the store plugin.

return: bool

supports_data_guarantee()   X-Ref
Returns true if the store instance guarantees data.

return: bool

supports_multiple_identifiers()   X-Ref
Returns true if the store instance supports multiple identifiers.

return: bool

supports_native_ttl()   X-Ref
Returns true if the store instance supports native ttl.

return: bool

is_searchable()   X-Ref
Returns true if the store instance is searchable.

return: bool

supports_dereferencing_objects()   X-Ref
Returns true if the store automatically dereferences objects.

return: bool

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

param: array $details An array containing the details of the store from the cache config.
return: cache_store

get_warnings()   X-Ref
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: string[] An array of warning strings from the store instance.

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