Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250620) (7d9030acd6e)
core_cache\factory Class Reference
Inheritance diagram for core_cache\factory:
core_cache\disabled_factory

Public Member Functions

 create_cache (definition $definition)
 Common public method to create a cache instance given a definition.
 
 create_cache_from_definition ($component, $area, array $identifiers=[], $unused=null)
 Creates a cache object given the parameters for a definition.
 
 create_cache_from_params ($mode, $component, $area, array $identifiers=[], array $options=[])
 Creates an ad-hoc cache from the given param.
 
 create_config_instance ($writer=false)
 Creates a cache config instance with the ability to write if required.
 
 create_definition ($component, $area, $unused=null)
 Creates a definition instance or returns the existing one if it has already been created.
 
 create_lock_instance (array $config)
 Returns a lock instance ready for use.
 
 create_store_from_config ($name, array $details, definition $definition)
 Creates a store instance given its name and configuration.
 
 get_adhoc_caches_in_use ()
 Gets all adhoc caches that have been used within this request.
 
 get_caches_in_use ()
 Returns the cache instances that have been used within this request.
 
 get_state ()
 Returns the current state of the cache API.
 
 get_store_instances_in_use (definition $definition)
 Returns an array of cache stores that have been initialised for use in definitions.
 
 is_disabled ()
 Returns true if the cache API has been disabled.
 
 is_initialising ()
 Returns true if the cache is currently initialising itself.
 
 is_updating ()
 Returns true if the cache is currently updating itself.
 
 reset_cache_instances ()
 Resets the stores, clearing the array of created stores.
 
 set_state ($state)
 Updates the state fo the cache API.
 
 stores_disabled ()
 Returns true if the cache stores have been disabled.
 
 updating_finished ()
 Informs the factory that the upgrading has finished.
 
 updating_started ()
 Informs the factory that the cache is currently updating itself.
 

Static Public Member Functions

static disable_stores ()
 Disables cache stores.
 
static get_administration_display_helper ()
 Returns an instance of the current display_helper.
 
static get_disabled_writer ()
 Gets the config_writer to use when caching is disabled.
 
static instance ($forcereload=false)
 Returns an instance of the factory class.
 
static reset ()
 Resets the arrays containing instantiated caches, stores, and config instances.
 

Public Attributes

const STATE_DISABLED = 10
 The cache has been disabled.
 
const STATE_ERROR_INITIALISING = 9
 The cache encountered an error while initialising.
 
const STATE_INITIALISING = 1
 The cache is in the process of initialising itself.
 
const STATE_READY = 3
 The cache is ready to use.
 
const STATE_SAVING = 2
 The cache is in the process of saving its configuration file.
 
const STATE_STORES_DISABLED = 11
 The cache stores have been disabled.
 
const STATE_UNINITIALISED = 0
 The cache has not been initialised yet.
 
const STATE_UPDATING = 4
 The cache is currently updating itself.
 

Protected Member Functions

 __construct ()
 Protected constructor, please use the static instance method.
 
 create_dummy_store (definition $definition)
 Creates a dummy store object for use when a loader has no potential stores to use.
 

Static Protected Member Functions

static disable ()
 Disables as much of the cache API as possible.
 

Protected Attributes

array $cachesfromdefinitions = []
 An array containing caches created for definitions.
 
array $cachesfromparams = []
 Array of caches created by parameters, ad-hoc definitions will have been used.
 
array $configs = []
 An array of configuration instances.
 
array $definitions = []
 An array of initialised definitions.
 
array $definitionstores = []
 An array of stores organised by definitions.
 
array $lockplugins = []
 An array of lock plugins.
 
int $state = 0
 The current state of the cache API.
 
array $stores = []
 An array of instantiated stores.
 

Static Protected Attributes

static core_cache local administration_display_helper $displayhelper = null
 The current cache display helper.
 
static factory $instance
 An instance of the factory class created upon the first request.
 

Member Function Documentation

◆ create_cache()

core_cache\factory::create_cache ( definition $definition)

Common public method to create a cache instance given a definition.

This is used by the static make methods.

Parameters
definition$definition
Return values
application_cache|session_cache|store
Exceptions
coding_exception

Reimplemented in core_cache\disabled_factory.

◆ create_cache_from_definition()

core_cache\factory::create_cache_from_definition ( $component,
$area,
array $identifiers = [],
$unused = null )

Creates a cache object given the parameters for a definition.

If a cache has already been created for the given definition then that cache instance will be returned.

Parameters
string$component
string$area
array$identifiers
string$unusedUsed to be data source aggregate however that was removed and this is now unused.
Return values
application_cache|session_cache|request_cache

Reimplemented in core_cache\disabled_factory.

◆ create_cache_from_params()

core_cache\factory::create_cache_from_params ( $mode,
$component,
$area,
array $identifiers = [],
array $options = [] )

Creates an ad-hoc cache from the given param.

If a cache has already been created using the same params then that cache instance will be returned.

Parameters
int$mode
string$component
string$area
array$identifiers
array$optionsAn array of options, available options are:
  • simplekeys : Set to true if the keys you will use are a-zA-Z0-9_
  • simpledata : Set to true if the type of the data you are going to store is scalar, or an array of scalar vars
  • staticacceleration : If set to true the cache will hold onto data passing through it.
  • staticaccelerationsize : The maximum number of items to hold onto for acceleration purposes.
Return values
application_cache|session_cache|request_cache

Reimplemented in core_cache\disabled_factory.

◆ create_config_instance()

core_cache\factory::create_config_instance ( $writer = false)

Creates a cache config instance with the ability to write if required.

Parameters
bool$writerIf set to true an instance that can update the configuration will be returned.
Return values
config|config_writer

Reimplemented in core_cache\disabled_factory.

◆ create_definition()

core_cache\factory::create_definition ( $component,
$area,
$unused = null )

Creates a definition instance or returns the existing one if it has already been created.

Parameters
string$component
string$area
string$unusedThis used to be data source aggregate - however that functionality has been removed and this argument is now unused.
Return values
definition
Exceptions
coding_exceptionIf the definition cannot be found.

Reimplemented in core_cache\disabled_factory.

◆ create_dummy_store()

core_cache\factory::create_dummy_store ( definition $definition)
protected

Creates a dummy store object for use when a loader has no potential stores to use.

Parameters
definition$definition
Return values
dummy_cachestore

◆ create_lock_instance()

core_cache\factory::create_lock_instance ( array $config)

Returns a lock instance ready for use.

Parameters
array$config
Return values
lockable_cache_interface

◆ create_store_from_config()

core_cache\factory::create_store_from_config ( $name,
array $details,
definition $definition )

Creates a store instance given its name and configuration.

If the store has already been instantiated then the original object will be returned. (reused)

Parameters
string$nameThe name of the store (must be unique remember)
array$details
definition$definitionThe definition to instantiate it for.
Return values
boolean|store

Reimplemented in core_cache\disabled_factory.

◆ disable()

static core_cache\factory::disable ( )
staticprotected

Disables as much of the cache API as possible.

All of the magic associated with the disabled cache is wrapped into this function. In switching out the factory for the disabled factory it gains full control over the initialisation of objects and can use all of the disabled alternatives. Simple!

This function has been marked as protected so that it cannot be abused through the public API presently. Perhaps in the future we will allow this, however as per the build up to the first release containing MUC it was decided that this was just to risky and abusable.

◆ disable_stores()

static core_cache\factory::disable_stores ( )
static

Disables cache stores.

The cache API will continue to function however none of the actual stores will be used. Instead the dummy store will be provided for all cache requests. This is useful in situations where you cannot be sure any stores are working.

In order to re-enable the cache you must call the cache factories static reset method: // Disable the cache factory. factory::disable_stores(); // Re-enable the cache factory by resetting it. factory::reset();

◆ get_adhoc_caches_in_use()

core_cache\factory::get_adhoc_caches_in_use ( )

Gets all adhoc caches that have been used within this request.

Return values
store[]Caches currently in use

◆ get_administration_display_helper()

static core_cache\factory::get_administration_display_helper ( )
static

Returns an instance of the current display_helper.

Return values
administration_helper

◆ get_caches_in_use()

core_cache\factory::get_caches_in_use ( )

Returns the cache instances that have been used within this request.

Since
Moodle 2.6
Return values
array

◆ get_disabled_writer()

static core_cache\factory::get_disabled_writer ( )
static

Gets the config_writer to use when caching is disabled.

This should only be called from disabled_factory.

Return values
config_writer

◆ get_state()

core_cache\factory::get_state ( )

Returns the current state of the cache API.

Return values
int

◆ get_store_instances_in_use()

core_cache\factory::get_store_instances_in_use ( definition $definition)

Returns an array of cache stores that have been initialised for use in definitions.

Parameters
definition$definition
Return values
array

◆ instance()

static core_cache\factory::instance ( $forcereload = false)
static

Returns an instance of the factory class.

Parameters
bool$forcereloadIf set to true a new factory instance will be created and used.
Return values
factory

Reimplemented in core_cache\disabled_factory.

◆ is_disabled()

core_cache\factory::is_disabled ( )

Returns true if the cache API has been disabled.

Return values
bool

Reimplemented in core_cache\disabled_factory.

◆ is_initialising()

core_cache\factory::is_initialising ( )

Returns true if the cache is currently initialising itself.

This includes both initialisation and saving the cache config file as part of that initialisation.

Return values
bool

◆ is_updating()

core_cache\factory::is_updating ( )

Returns true if the cache is currently updating itself.

Return values
bool

◆ reset_cache_instances()

core_cache\factory::reset_cache_instances ( )

Resets the stores, clearing the array of created stores.

Cache objects still held onto by the code that initialised them will remain as is however all future requests for a cache/store will lead to a new instance being re-initialised.

◆ set_state()

core_cache\factory::set_state ( $state)

Updates the state fo the cache API.

Parameters
int$state
Return values
bool

◆ stores_disabled()

core_cache\factory::stores_disabled ( )

Returns true if the cache stores have been disabled.

Return values
bool

◆ updating_finished()

core_cache\factory::updating_finished ( )

Informs the factory that the upgrading has finished.

This forces the state back to ready.

◆ updating_started()

core_cache\factory::updating_started ( )

Informs the factory that the cache is currently updating itself.

This forces the state to upgrading and can only be called once the cache is ready to use. Calling it ensure we don't try to reinstantite things when requesting cache definitions that don't exist yet.


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