Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
cache_definition Class Reference

Public Member Functions

 can_use_localstore ()
 Returns true if this definition allows local storage to be used for caching. More...
 
 generate_definition_hash ()
 Generates a hash of this definition and returns it. More...
 
 generate_multi_key_parts ()
 Generates a multi key prefix for this definition. More...
 
 generate_single_key_prefix ()
 Generates a single key prefix for this definition. More...
 
 get_area ()
 Returns the area this definition is associated with. More...
 
 get_cache_class ()
 Returns the cache loader class that should be used for this definition. More...
 
 get_component ()
 Returns the component this definition is associated with. More...
 
 get_data_source ()
 Returns an instance of the data source class used for this definition. More...
 
 get_id ()
 Returns the id of this definition. More...
 
 get_identifiers ()
 Returns the identifiers that are being used for this definition. More...
 
 get_invalidation_events ()
 Returns all of the invalidation events for this definition. More...
 
 get_maxsize ()
 Returns the maximum number of items allowed in this cache. More...
 
 get_mode ()
 Returns the mode of this definition. More...
 
 get_name ()
 Returns the name for this definition. More...
 
 get_persistent_max_size ()
 Please call cache_definition::get_static_acceleration_size() instead. More...
 
 get_requirements_bin ()
 Returns the requirements of this definition as a binary flag. More...
 
 get_selected_sharing_option ()
 Returns the user selected sharing option for this definition. More...
 
 get_sharing_options ()
 Returns the possible sharing options that can be used with this defintion. More...
 
 get_static_acceleration_size ()
 Returns the max size for the static acceleration array. More...
 
 get_ttl ()
 Returns the ttl in seconds for this definition if there is one, or null if not. More...
 
 get_user_input_sharing_key ()
 Returns the user entered sharing key for this definition. More...
 
 has_data_source ()
 Returns true if this definition has an associated data source. More...
 
 has_invalidation_events ()
 Check if the definition has any invalidation events. More...
 
 has_required_identifiers ()
 Returns true if this definition requires identifiers. More...
 
 invalidates_on_event ($event)
 Check if this definition should invalidate on the given event. More...
 
 is_for_mappings_only ()
 Returns true if this definition should only be used with mappings. More...
 
 require_data_guarantee ()
 Returns true if this definition requires a data guarantee from the cache stores being used. More...
 
 require_locking ()
 Returns true if this definition requires locking functionality. More...
 
 require_locking_read ()
 Returns true if this definition requires read locking. More...
 
 require_locking_write ()
 Returns true if this definition requires write locking. More...
 
 require_multiple_identifiers ()
 Returns true if this definition requires that the cache stores support multiple identifiers. More...
 
 require_searchable ()
 Returns true if this definition requires a searchable cache. More...
 
 set_identifiers (array $identifiers=array())
 Sets the identifiers for this definition, or updates them if they have already been set. More...
 
 should_be_persistent ()
 Please call cache_definition::use_static_acceleration() instead. More...
 
 use_static_acceleration ()
 Returns true if we should hold onto the data flowing through the cache. More...
 
 uses_simple_data ()
 Returns true if the data is known to be scalar or array of scalar. More...
 
 uses_simple_keys ()
 Returns true if this definition is using simple keys. More...
 

Static Public Member Functions

static load ($id, array $definition, $unused=null)
 Creates a cache definition given a definition from the cache configuration or from a caches.php file. More...
 
static load_adhoc ($mode, $component, $area, array $options=array())
 Creates an ah-hoc cache definition given the required params. More...
 

Public Attributes

const SHARING_ALL = 1
 The cache can be shared with everyone.
 
const SHARING_DEFAULT = 2
 The default sharing option that gets used if none have been selected. More...
 
const SHARING_DEFAULTOPTIONS = 15
 The default sharing options available. More...
 
const SHARING_INPUT = 8
 The cache can be shared with other sites using the same key.
 
const SHARING_SITEID = 2
 The cache can be shared with other sites using the same siteid.
 
const SHARING_VERSION = 4
 The cache can be shared with other sites of the same version.
 

Protected Member Functions

 get_cache_identifier ()
 Returns a cache identification string. More...
 

Protected Attributes

string $area
 The area this definition is associated with.
 
bool $canuselocalstore = false
 Whether this cache supports local storages.
 
string $component
 The component this definition is associated with.
 
string $datasource = null
 The data source class to use with this definition.
 
string $datasourcefile = null
 The file in which the data source class exists. More...
 
string $definitionhash = null
 A hash identifier of this definition.
 
string $id
 The identifier for the definition.
 
array $identifiers = null
 An array of identifiers provided to this cache when it was initialised.
 
array $invalidationevents = array()
 An array of events that should cause this cache to invalidate.
 
array $keyprefixmulti = null
 Key prefix to use with cache stores that support multi keys.
 
string $keyprefixsingle = null
 Key prefix for use with single key cache stores.
 
bool $mappingsonly = false
 Set to true if this cache should only use mapped cache stores and not the default mode cache store.
 
int $maxsize = null
 Sets the maximum number of items that can exist in the cache. More...
 
int $mode
 The mode for the defintion. More...
 
string $overrideclass = null
 The class to use as the cache loader for this definition.
 
string $overrideclassfile = null
 The file in which the override class exists. More...
 
bool $requiredataguarantee = false
 If set to true then only stores that guarantee data may be used with this definition.
 
array $requireidentifiers = array()
 An array of identifiers that must be provided when the definition is used to create a cache.
 
bool $requirelocking = false
 If set to true then we know that this definition requires the locking functionality. More...
 
bool $requirelockingread = false
 Set to true if this definition requires read locking.
 
bool $requirelockingwrite = false
 Gets set to true if this definition requires write locking.
 
bool $requiremultipleidentifiers = false
 If set to true then only stores that support multple identifiers may be used with this definition.
 
bool $requiresearchable = false
 Gets set to true if this definition requires searchable stores. More...
 
int $selectedsharingoption = self::SHARING_DEFAULT
 The selected sharing option. More...
 
int $sharingoptions
 The selected sharing mode for this definition.
 
bool $simpledata = false
 Set to true if we know the data is scalar or array of scalar.
 
bool $simplekeys = false
 If set to true we know the keys are simple. More...
 
bool $staticacceleration = false
 Set to true if the cache should hold onto items passing through it to speed up subsequent requests.
 
int $staticaccelerationsize = false
 The maximum number of items that static acceleration cache should hold onto.
 
int $ttl = 0
 The TTL for data in this cache. More...
 
string $userinputsharingkey = ''
 The user input key to use if the SHARING_INPUT option has been selected. More...
 

Member Function Documentation

◆ can_use_localstore()

cache_definition::can_use_localstore ( )

Returns true if this definition allows local storage to be used for caching.

Since
Moodle 3.1.0
Return values
bool

◆ generate_definition_hash()

cache_definition::generate_definition_hash ( )

Generates a hash of this definition and returns it.

Return values
string

◆ generate_multi_key_parts()

cache_definition::generate_multi_key_parts ( )

Generates a multi key prefix for this definition.

Return values
array

◆ generate_single_key_prefix()

cache_definition::generate_single_key_prefix ( )

Generates a single key prefix for this definition.

Return values
string

◆ get_area()

cache_definition::get_area ( )

Returns the area this definition is associated with.

Return values
string

◆ get_cache_class()

cache_definition::get_cache_class ( )

Returns the cache loader class that should be used for this definition.

Return values
string

◆ get_cache_identifier()

cache_definition::get_cache_identifier ( )
protected

Returns a cache identification string.

Return values
stringA string to be used as part of keys.

◆ get_component()

cache_definition::get_component ( )

Returns the component this definition is associated with.

Return values
string

◆ get_data_source()

cache_definition::get_data_source ( )

Returns an instance of the data source class used for this definition.

Return values
cache_data_source
Exceptions
coding_exception

◆ get_id()

cache_definition::get_id ( )

Returns the id of this definition.

Return values
string

◆ get_identifiers()

cache_definition::get_identifiers ( )

Returns the identifiers that are being used for this definition.

Return values
array

◆ get_invalidation_events()

cache_definition::get_invalidation_events ( )

Returns all of the invalidation events for this definition.

Return values
array

◆ get_maxsize()

cache_definition::get_maxsize ( )

Returns the maximum number of items allowed in this cache.

Return values
int

◆ get_mode()

cache_definition::get_mode ( )

Returns the mode of this definition.

Return values
intOne more cache_store::MODE_

◆ get_name()

cache_definition::get_name ( )

Returns the name for this definition.

Return values
string

◆ get_persistent_max_size()

cache_definition::get_persistent_max_size ( )

◆ get_requirements_bin()

cache_definition::get_requirements_bin ( )

Returns the requirements of this definition as a binary flag.

Return values
int

◆ get_selected_sharing_option()

cache_definition::get_selected_sharing_option ( )

Returns the user selected sharing option for this definition.

Return values
int

◆ get_sharing_options()

cache_definition::get_sharing_options ( )

Returns the possible sharing options that can be used with this defintion.

Return values
int

◆ get_static_acceleration_size()

cache_definition::get_static_acceleration_size ( )

Returns the max size for the static acceleration array.

Return values
int

◆ get_ttl()

cache_definition::get_ttl ( )

Returns the ttl in seconds for this definition if there is one, or null if not.

Return values
int|null

◆ get_user_input_sharing_key()

cache_definition::get_user_input_sharing_key ( )

Returns the user entered sharing key for this definition.

Return values
string

◆ has_data_source()

cache_definition::has_data_source ( )

Returns true if this definition has an associated data source.

Return values
bool

◆ has_invalidation_events()

cache_definition::has_invalidation_events ( )

Check if the definition has any invalidation events.

Return values
boolTrue if it does, false otherwise

◆ has_required_identifiers()

cache_definition::has_required_identifiers ( )

Returns true if this definition requires identifiers.

Parameters
bool

◆ invalidates_on_event()

cache_definition::invalidates_on_event (   $event)

Check if this definition should invalidate on the given event.

Parameters
string$event
Return values
boolTrue if the definition should invalidate on the event. False otherwise.

◆ is_for_mappings_only()

cache_definition::is_for_mappings_only ( )

Returns true if this definition should only be used with mappings.

Return values
bool

◆ load()

static cache_definition::load (   $id,
array  $definition,
  $unused = null 
)
static

Creates a cache definition given a definition from the cache configuration or from a caches.php file.

Parameters
string$id
array$definition
string$unusedUsed to be datasourceaggregate but that was removed and this is now unused.
Return values
cache_definition
Exceptions
coding_exception

◆ load_adhoc()

static cache_definition::load_adhoc (   $mode,
  $component,
  $area,
array  $options = array() 
)
static

Creates an ah-hoc cache definition given the required params.

Please note that when using an adhoc definition you cannot set any of the optional params. This is because we cannot guarantee consistent access and we don't want to mislead people into thinking that.

Parameters
int$modeOne of cache_store::MODE_*
string$componentThe component this definition relates to.
string$areaThe area this definition relates to.
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
  • overrideclass : The class to use as the loader.
  • staticacceleration : If set to true the cache will hold onto data passing through it.
  • staticaccelerationsize : Set it to an int to limit the size of the staticacceleration cache.
Return values
cache_application|cache_session|cache_request

◆ require_data_guarantee()

cache_definition::require_data_guarantee ( )

Returns true if this definition requires a data guarantee from the cache stores being used.

Return values
bool

◆ require_locking()

cache_definition::require_locking ( )

Returns true if this definition requires locking functionality.

Either read or write locking.

Return values
bool

◆ require_locking_read()

cache_definition::require_locking_read ( )

Returns true if this definition requires read locking.

Return values
bool

◆ require_locking_write()

cache_definition::require_locking_write ( )

Returns true if this definition requires write locking.

Return values
bool

◆ require_multiple_identifiers()

cache_definition::require_multiple_identifiers ( )

Returns true if this definition requires that the cache stores support multiple identifiers.

Return values
bool

◆ require_searchable()

cache_definition::require_searchable ( )

Returns true if this definition requires a searchable cache.

Since
Moodle 2.4.4
Return values
bool

◆ set_identifiers()

cache_definition::set_identifiers ( array  $identifiers = array())

Sets the identifiers for this definition, or updates them if they have already been set.

Parameters
array$identifiers
Return values
boolfalse if no identifiers where changed, true otherwise.
Exceptions
coding_exception

◆ should_be_persistent()

cache_definition::should_be_persistent ( )

◆ use_static_acceleration()

cache_definition::use_static_acceleration ( )

Returns true if we should hold onto the data flowing through the cache.

If set to true data flowing through the cache will be stored in a static variable to make subsequent requests for the data much faster.

Return values
bool

◆ uses_simple_data()

cache_definition::uses_simple_data ( )

Returns true if the data is known to be scalar or array of scalar.

Return values
bool

◆ uses_simple_keys()

cache_definition::uses_simple_keys ( )

Returns true if this definition is using simple keys.

Simple keys contain only a-zA-Z0-9_

Return values
bool

Member Data Documentation

◆ $datasourcefile

string cache_definition::$datasourcefile = null
protected

The file in which the data source class exists.

This will be included if required.

◆ $maxsize

int cache_definition::$maxsize = null
protected

Sets the maximum number of items that can exist in the cache.

Please note this isn't a hard limit, and doesn't need to be enforced by the caches. They can choose to do so optionally.

◆ $mode

int cache_definition::$mode
protected

The mode for the defintion.

One of cache_store::MODE_*

◆ $overrideclassfile

string cache_definition::$overrideclassfile = null
protected

The file in which the override class exists.

This will be included if required. Absolute path

◆ $requirelocking

bool cache_definition::$requirelocking = false
protected

If set to true then we know that this definition requires the locking functionality.

This gets set during construction based upon the settings requirelockingread and requirelockingwrite.

◆ $requiresearchable

bool cache_definition::$requiresearchable = false
protected

Gets set to true if this definition requires searchable stores.

Since
Moodle 2.4.4

◆ $selectedsharingoption

int cache_definition::$selectedsharingoption = self::SHARING_DEFAULT
protected

The selected sharing option.

One of self::SHARING_*

◆ $simplekeys

bool cache_definition::$simplekeys = false
protected

If set to true we know the keys are simple.

a-zA-Z0-9_

◆ $ttl

int cache_definition::$ttl = 0
protected

The TTL for data in this cache.

Please don't use this, instead use event driven invalidation.

◆ $userinputsharingkey

string cache_definition::$userinputsharingkey = ''
protected

The user input key to use if the SHARING_INPUT option has been selected.

Must be ALPHANUMEXT

◆ SHARING_DEFAULT

const cache_definition::SHARING_DEFAULT = 2

The default sharing option that gets used if none have been selected.

SiteID. It is the most restrictive.

◆ SHARING_DEFAULTOPTIONS

const cache_definition::SHARING_DEFAULTOPTIONS = 15

The default sharing options available.

All + SiteID + Version + Input.


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