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.
/cache/ -> locallib.php (source)

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

The supplementary cache API. This file is part of Moodle's cache API, affectionately called MUC. It contains elements of the API that are not required in order to use caching. Things in here are more in line with administration and management of the cache setup and configuration.

Copyright: 2012 Sam Hemelryk
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1267 lines (53 kb)
Included or required:0 times
Referenced: 11 times
Includes or requires: 1 file
 cache/lib.php

Defines 2 classes


Class: cache_config_writer  - X-Ref

Cache configuration writer.

This class should only be used when you need to write to the config, all read operations exist within the cache_config.

instance()   X-Ref
Returns an instance of the configuration writer.

return: cache_config_writer

config_save()   X-Ref
Saves the current configuration.

Exceptions within this function are tolerated but must be of type cache_exception.
They are caught during initialisation and written to the error log. This is required in order to avoid
infinite loop situations caused by the cache throwing exceptions during its initialisation.

generate_configuration_array()   X-Ref
Generates a configuration array suitable to be written to the config file.

return: array

add_store_instance($name, $plugin, array $configuration = array()   X-Ref
Adds a plugin instance.

This function also calls save so you should redirect immediately, or at least very shortly after
calling this method.

param: string $name The name for the instance (must be unique)
param: string $plugin The name of the plugin.
param: array $configuration The configuration data for the plugin instance.
return: bool

add_lock_instance($name, $plugin, $configuration = array()   X-Ref
Adds a new lock instance to the config file.

param: string $name The name the user gave the instance. PARAM_ALHPANUMEXT
param: string $plugin The plugin we are creating an instance of.
param: string $configuration Configuration data from the config instance.

delete_lock_instance($name)   X-Ref
Deletes a lock instance given its name.

param: string $name The name of the plugin, PARAM_ALPHANUMEXT.
return: bool

set_mode_mappings(array $modemappings)   X-Ref
Sets the mode mappings.

These determine the default caches for the different modes.
This function also calls save so you should redirect immediately, or at least very shortly after
calling this method.

param: array $modemappings
return: bool

edit_store_instance($name, $plugin, $configuration)   X-Ref
Edits a give plugin instance.

The plugin instance is determined by its name, hence you cannot rename plugins.
This function also calls save so you should redirect immediately, or at least very shortly after
calling this method.

param: string $name
param: string $plugin
param: array $configuration
return: bool

delete_store_instance($name)   X-Ref
Deletes a store instance.

This function also calls save so you should redirect immediately, or at least very shortly after
calling this method.

param: string $name The name of the instance to delete.
return: bool

create_default_configuration($forcesave = false)   X-Ref
Creates the default configuration and saves it.

This function calls config_save, however it is safe to continue using it afterwards as this function should only ever
be called when there is no configuration file already.

param: bool $forcesave If set to true then we will forcefully save the default configuration file.
return: true|array Returns true if the default configuration was successfully created.

get_default_stores()   X-Ref
Returns an array of default stores for use.

return: array

update_default_config_stores()   X-Ref
Updates the default stores within the MUC config file.


update_definitions($coreonly = false)   X-Ref
Updates the definition in the configuration from those found in the cache files.

Calls config_save further down, you should redirect immediately or asap after calling this method.

param: bool $coreonly If set to true only core definitions will be updated.

locate_definitions($coreonly = false)   X-Ref
Locates all of the definition files.

param: bool $coreonly If set to true only core definitions will be updated.
return: array

write_definitions_to_cache(array $definitions)   X-Ref
Writes the updated definitions for the config file.

param: array $definitions

load_caches_file($file)   X-Ref
Loads the caches file if it exists.

param: string $file Absolute path to the file.
return: array

set_definition_mappings($definition, $mappings)   X-Ref
Sets the mappings for a given definition.

param: string $definition
param: array $mappings

update_site_identifier($siteidentifier)   X-Ref
Update the site identifier stored by the cache API.

param: string $siteidentifier
return: string The new site identifier.

set_definition_sharing($definition, $sharingoption, $userinputsharingkey = null)   X-Ref
Sets the selected sharing options and key for a definition.

param: string $definition The name of the definition to set for.
param: int $sharingoption The sharing option to set.
param: string|null $userinputsharingkey The user input key or null.

Class: cache_administration_helper  - X-Ref

A cache helper for administration tasks

get_store_instance_summaries()   X-Ref
Returns an array containing all of the information about stores a renderer needs.

return: array

get_store_plugin_summaries()   X-Ref
Returns an array of information about plugins, everything a renderer needs.

return: array for each store, an array containing various information about each store.

get_definition_summaries()   X-Ref
Returns an array about the definitions. All the information a renderer needs.

return: array for each store, an array containing various information about each store.

get_definition_sharing_options($sharingoption, $isselectedoptions = true)   X-Ref
Given a sharing option hash this function returns an array of strings that can be used to describe it.

param: int $sharingoption The sharing option hash to get strings for.
param: bool $isselectedoptions Set to true if the strings will be used to view the selected options.
return: array An array of lang_string's.

get_definition_actions(context $context, array $definitionsummary)   X-Ref
Returns all of the actions that can be performed on a definition.

param: context $context the system context.
param: array $definitionsummary information about this cache, from the array returned by
return: array of actions. Each action is an array with two elements, 'text' and 'url'.

get_store_instance_actions($name, array $storedetails)   X-Ref
Returns all of the actions that can be performed on a store.

param: string $name The name of the store
param: array $storedetails information about this store, from the array returned by
return: array of actions. Each action is an array with two elements, 'text' and 'url'.

get_store_plugin_actions($name, array $plugindetails)   X-Ref
Returns all of the actions that can be performed on a plugin.

param: string $name The name of the plugin
param: array $plugindetails information about this store, from the array returned by
param: array $plugindetails
return: array

get_add_store_form($plugin)   X-Ref
Returns a form that can be used to add a store instance.

param: string $plugin The plugin to add an instance of
return: cachestore_addinstance_form

get_edit_store_form($plugin, $store)   X-Ref
Returns a form that can be used to edit a store instance.

param: string $plugin
param: string $store
return: cachestore_addinstance_form

get_possible_locks_for_stores($plugindir, $plugin)   X-Ref
Returns an array of suitable lock instances for use with this plugin, or false if the plugin handles locking itself.

param: string $plugindir
param: string $plugin
return: array|false

get_store_configuration_from_data(stdClass $data)   X-Ref
Processes the results of the add/edit instance form data for a plugin returning an array of config information suitable to
store in configuration.

param: stdClass $data The mform data.
return: array

get_definition_store_options($component, $area)   X-Ref
Get an array of stores that are suitable to be used for a given definition.

param: string $component
param: string $area
return: array Array containing 3 elements

get_default_mode_stores()   X-Ref
Get the default stores for all modes.

return: array An array containing sub-arrays, one for each mode.

get_lock_summaries()   X-Ref
Returns an array summarising the locks available in the system


get_addable_lock_options()   X-Ref
Returns an array of lock plugins for which we can add an instance.

Suitable for use within an mform select element.

return: array

get_add_lock_form($plugin, array $lockplugin = null)   X-Ref
Gets the form to use when adding a lock instance.

param: string $plugin
param: array $lockplugin
return: cache_lock_form

get_lock_configuration_from_data($plugin, $data)   X-Ref
Gets configuration data from a new lock instance form.

param: string $plugin
param: stdClass $data
return: array