Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250706) (a6b17d8f6bd)
core_cache\helper Class Reference
Inheritance diagram for core_cache\helper:
core_cache\administration_helper core_cache\local\administration_display_helper

Static Public Member Functions

static clean_old_session_data ($output=false)
 Cleans old session data from cache stores used for session based definitions.
 
static cron ()
 Runs cron routines for MUC.
 
static early_get_cache_plugins ()
 Returns an array of plugins without using core methods.
 
static get_cache_stores (definition $definition)
 Returns the cache stores to be used with the given definition.
 
static get_cachelock_for_store (store $store)
 Returns a locakable_cache_interface instance suitable for use with the store.
 
static get_class_for_mode ($mode)
 Returns the class for use as a cache loader for the given mode.
 
static get_definition_name ($definition)
 Returns the translated name of the definition.
 
static get_site_identifier ()
 Returns the site identifier.
 
static get_site_version ()
 Returns the site version.
 
static get_stats ()
 Return the stats collected so far.
 
static get_stores_suitable_for_definition (definition $definition)
 Returns stores suitable for use with a given definition.
 
static get_stores_suitable_for_mode_default ()
 Returns an array of stores that would meet the requirements for every definition.
 
static hash_key ($key, definition $definition)
 Hashes a descriptive key to make it shorter and still unique.
 
static invalidate_by_definition ($component, $area, array $identifiers=[], $keys=[])
 Invalidates a given set of keys from a given definition.
 
static invalidate_by_event ($event, array $keys)
 Invalidates a given set of keys by means of an event.
 
static is_cluster_available ()
 Checks whether the cluster mode is available in PHP.
 
static purge_all ($usewriter=false)
 Purge all of the cache stores of all of their data.
 
static purge_by_definition ($component, $area, array $identifiers=[])
 Purges the cache for a specific definition.
 
static purge_by_event ($event)
 Purges a cache of all information on a given event.
 
static purge_store ($storename, ?config $config=null)
 Purges a store given its name.
 
static purge_stores_used_by_definition ($component, $area)
 Purges all of the stores used by a definition.
 
static ready_for_early_init ()
 Returns true if the cache API can be initialised before Moodle has finished initialising itself.
 
static record_cache_hit ( $store, $definition, int $hits=1, int $readbytes=store::IO_BYTES_NOT_SUPPORTED,)
 Record a cache hit in the stats for the given store and definition.
 
static record_cache_miss ($store, $definition, $misses=1)
 Record a cache miss in the stats for the given store and definition.
 
static record_cache_set ( $store, $definition, int $sets=1, int $writebytes=store::IO_BYTES_NOT_SUPPORTED)
 Record a cache set in the stats for the given store and definition.
 
static result_found ($value)
 A helper to determine whether a result was found.
 
static update_definitions ($coreonly=false)
 Finds all definitions and updates them within the cache config file.
 
static update_site_identifier ($siteidentifier)
 Update the site identifier stored by the cache API.
 
static warnings (?array $stores=null)
 Returns an array of warnings from the cache API.
 

Protected Member Functions

 __construct ()
 Constructs an instance of the helper class.
 

Static Protected Member Functions

static ensure_ready_for_stats ($store, $storeclass, $definition, $mode=store::MODE_APPLICATION)
 Ensure that the stats array is ready to collect information for the given store and definition.
 
static get_definition_stat_id_and_mode ($definition)
 Returns a string to describe the definition.
 
static initialise_cachestore_instances (array $stores, definition $definition)
 Internal function for initialising an array of stores against a given cache definition.
 
static instance ()
 Returns an instance of the helper.
 

Protected Attributes

array $definitions = []
 Used as a data store for initialised definitions.
 
array $stores = []
 Used as a data store for initialised cache stores We use this because we want to avoid establishing multiple instances of a single store.
 

Static Protected Attributes

static self $instance
 The instance of the cache helper.
 
static string $siteidentifier = null
 The site identifier used by the cache.
 
static array $stats = []
 Statistics gathered by the cache API during its operation will be used here.
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

core_cache\helper::__construct ( )
protected

Constructs an instance of the helper class.

Again for internal use only.

Reimplemented in core_cache\local\administration_display_helper.

Member Function Documentation

◆ clean_old_session_data()

static core_cache\helper::clean_old_session_data ( $output = false)
static

Cleans old session data from cache stores used for session based definitions.

Parameters
bool$outputIf set to true output will be given.

◆ early_get_cache_plugins()

static core_cache\helper::early_get_cache_plugins ( )
static

Returns an array of plugins without using core methods.

This function explicitly does NOT use core functions as it will in some circumstances be called before Moodle has finished initialising. This happens when loading configuration for instance.

Return values
array

◆ ensure_ready_for_stats()

static core_cache\helper::ensure_ready_for_stats ( $store,
$storeclass,
$definition,
$mode = store::MODE_APPLICATION )
staticprotected

Ensure that the stats array is ready to collect information for the given store and definition.

Parameters
string$store
string$storeclass
string$definitionA string that identifies the definition.
int$modeOne of store::MODE_*. Since 2.9.

◆ get_cache_stores()

static core_cache\helper::get_cache_stores ( definition $definition)
static

Returns the cache stores to be used with the given definition.

Parameters
definition$definition
Return values
array

◆ get_cachelock_for_store()

static core_cache\helper::get_cachelock_for_store ( store $store)
static

Returns a locakable_cache_interface instance suitable for use with the store.

Parameters
store$store
Return values
lockable_cache_interface

◆ get_class_for_mode()

static core_cache\helper::get_class_for_mode ( $mode)
static

Returns the class for use as a cache loader for the given mode.

Parameters
int$modeOne of store::MODE_
Return values
string
Exceptions
coding_exception

◆ get_definition_name()

static core_cache\helper::get_definition_name ( $definition)
static

Returns the translated name of the definition.

Parameters
definition$definition
Return values
lang_string

◆ get_definition_stat_id_and_mode()

static core_cache\helper::get_definition_stat_id_and_mode ( $definition)
staticprotected

Returns a string to describe the definition.

This method supports the definition as a string due to legacy requirements. It is backwards compatible when a string is passed but is not accurate.

Since
2.9
Parameters
definition | string$definition
Return values
string

◆ get_site_identifier()

static core_cache\helper::get_site_identifier ( )
static

Returns the site identifier.

Return values
string

◆ get_site_version()

static core_cache\helper::get_site_version ( )
static

Returns the site version.

Return values
string

◆ get_stats()

static core_cache\helper::get_stats ( )
static

Return the stats collected so far.

Return values
array

◆ get_stores_suitable_for_definition()

static core_cache\helper::get_stores_suitable_for_definition ( definition $definition)
static

Returns stores suitable for use with a given definition.

Parameters
definition$definition
Return values
store[]

◆ get_stores_suitable_for_mode_default()

static core_cache\helper::get_stores_suitable_for_mode_default ( )
static

Returns an array of stores that would meet the requirements for every definition.

These stores would be 100% suitable to map as defaults for cache modes.

Return values
array[]An array of stores, keys are the store names.

◆ hash_key()

static core_cache\helper::hash_key ( $key,
definition $definition )
static

Hashes a descriptive key to make it shorter and still unique.

Parameters
string | int$key
definition$definition
Return values
string

◆ initialise_cachestore_instances()

static core_cache\helper::initialise_cachestore_instances ( array $stores,
definition $definition )
staticprotected

Internal function for initialising an array of stores against a given cache definition.

Parameters
array$stores
definition$definition
Return values
store[]

◆ instance()

static core_cache\helper::instance ( )
staticprotected

Returns an instance of the helper.

This is designed for internal use only and acts as a static store. @staticvar null $instance

Return values
self

◆ invalidate_by_definition()

static core_cache\helper::invalidate_by_definition ( $component,
$area,
array $identifiers = [],
$keys = [] )
static

Invalidates a given set of keys from a given definition.

Todo
Invalidating by definition should also add to the event cache so that sessions can be invalidated (when required).
Parameters
string$component
string$area
array$identifiers
array | string | int$keys
Return values
boolean
Exceptions
coding_exception

◆ invalidate_by_event()

static core_cache\helper::invalidate_by_event ( $event,
array $keys )
static

Invalidates a given set of keys by means of an event.

Events cannot determine what identifiers might need to be cleared. Event based purge and invalidation are only supported on caches without identifiers.

Parameters
string$event
array$keys

◆ is_cluster_available()

static core_cache\helper::is_cluster_available ( )
static

Checks whether the cluster mode is available in PHP.

Return values
boolReturn true if the PHP supports redis cluster, otherwise false.

◆ purge_all()

static core_cache\helper::purge_all ( $usewriter = false)
static

Purge all of the cache stores of all of their data.

Think twice before calling this method. It will purge ALL caches regardless of whether they have been used recently or anything. This will involve full setup of the cache + the purge operation. On a site using caching heavily this WILL be painful.

Parameters
bool$usewriterIf set to true the config_writer class is used. This class is special as it avoids it is still usable when caches have been disabled. Please use this option only if you really must. It's purpose is to allow the cache to be purged when it would be otherwise impossible.

◆ purge_by_definition()

static core_cache\helper::purge_by_definition ( $component,
$area,
array $identifiers = [] )
static

Purges the cache for a specific definition.

Parameters
string$component
string$area
array$identifiers
Return values
bool

◆ purge_by_event()

static core_cache\helper::purge_by_event ( $event)
static

Purges a cache of all information on a given event.

Events cannot determine what identifiers might need to be cleared. Event based purge and invalidation are only supported on caches without identifiers.

Parameters
string$event

◆ purge_store()

static core_cache\helper::purge_store ( $storename,
?config $config = null )
static

Purges a store given its name.

Parameters
string$storename
config | null$config
Return values
bool

◆ purge_stores_used_by_definition()

static core_cache\helper::purge_stores_used_by_definition ( $component,
$area )
static

Purges all of the stores used by a definition.

Unlike helper::purge_by_definition this purges all of the data from the stores not just the data relating to the definition. This function is useful when you must purge a definition that requires setup but you don't want to set it up.

Parameters
string$component
string$area

◆ ready_for_early_init()

static core_cache\helper::ready_for_early_init ( )
static

Returns true if the cache API can be initialised before Moodle has finished initialising itself.

This check is essential when trying to cache the likes of configuration information. It checks to make sure that the cache configuration file has been created which allows use to set up caching when ever is required.

Return values
bool

◆ record_cache_hit()

static core_cache\helper::record_cache_hit ( $store,
$definition,
int $hits = 1,
int $readbytes = store::IO_BYTES_NOT_SUPPORTED )
static

Record a cache hit in the stats for the given store and definition.

In Moodle 2.9 the $definition argument changed from accepting only a string to accepting a string or a definition instance. It is preferable to pass a cache definition instance.

In Moodle 3.9 the first argument changed to also accept a store.

◆ record_cache_miss()

static core_cache\helper::record_cache_miss ( $store,
$definition,
$misses = 1 )
static

Record a cache miss in the stats for the given store and definition.

In Moodle 2.9 the $definition argument changed from accepting only a string to accepting a string or a definition instance. It is preferable to pass a cache definition instance.

In Moodle 3.9 the first argument changed to also accept a store.

◆ record_cache_set()

static core_cache\helper::record_cache_set ( $store,
$definition,
int $sets = 1,
int $writebytes = store::IO_BYTES_NOT_SUPPORTED )
static

Record a cache set in the stats for the given store and definition.

In Moodle 2.9 the $definition argument changed from accepting only a string to accepting a string or a definition instance. It is preferable to pass a cache definition instance.

In Moodle 3.9 the first argument changed to also accept a store.

◆ result_found()

static core_cache\helper::result_found ( $value)
static

A helper to determine whether a result was found.

This has been deemed required after people have been confused by the fact that [] == false.

Parameters
mixed$value
Return values
bool

◆ update_definitions()

static core_cache\helper::update_definitions ( $coreonly = false)
static

Finds all definitions and updates them within the cache config file.

Parameters
bool$coreonlyIf set to true only core definitions will be updated.

◆ update_site_identifier()

static core_cache\helper::update_site_identifier ( $siteidentifier)
static

Update the site identifier stored by the cache API.

Parameters
string$siteidentifier
Return values
stringThe new site identifier.

◆ warnings()

static core_cache\helper::warnings ( ?array $stores = null)
static

Returns an array of warnings from the cache API.

The warning returned here are for things like conflicting store instance configurations etc. These get shown on the admin notifications page for example.

Parameters
array | null$storesAn array of stores to get warnings for, or null for all.
Return values
string[]

Member Data Documentation

◆ $siteidentifier

string core_cache\helper::$siteidentifier = null
staticprotected

The site identifier used by the cache.

Set the first time get_site_identifier is called.


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