Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
|
The cache definition class. More...
Public Member Functions | |
can_use_localstore () | |
Returns true if this definition allows local storage to be used for caching. | |
generate_definition_hash () | |
Generates a hash of this definition and returns it. | |
generate_multi_key_parts () | |
Generates a multi key prefix for this definition. | |
generate_single_key_prefix () | |
Generates a single key prefix for this definition. | |
get_area () | |
Returns the area this definition is associated with. | |
get_cache_class () | |
Returns the cache loader class that should be used for this definition. | |
get_component () | |
Returns the component this definition is associated with. | |
get_data_source () | |
Returns an instance of the data source class used for this definition. | |
get_id () | |
Returns the id of this definition. | |
get_identifiers () | |
Returns the identifiers that are being used for this definition. | |
get_invalidation_events () | |
Returns all of the invalidation events for this definition. | |
get_maxsize () | |
Returns the maximum number of items allowed in this cache. | |
get_mode () | |
Returns the mode of this definition. | |
get_name () | |
Returns the name for this definition. | |
get_persistent_max_size () | |
Please call cache_definition::get_static_acceleration_size() instead. | |
get_requirements_bin () | |
Returns the requirements of this definition as a binary flag. | |
get_selected_sharing_option () | |
Returns the user selected sharing option for this definition. | |
get_sharing_options () | |
Returns the possible sharing options that can be used with this defintion. | |
get_static_acceleration_size () | |
Returns the max size for the static acceleration array. | |
get_ttl () | |
Returns the ttl in seconds for this definition if there is one, or null if not. | |
get_user_input_sharing_key () | |
Returns the user entered sharing key for this definition. | |
has_data_source () | |
Returns true if this definition has an associated data source. | |
has_invalidation_events () | |
Check if the definition has any invalidation events. | |
has_required_identifiers () | |
Returns true if this definition requires identifiers. | |
invalidates_on_event ($event) | |
Check if this definition should invalidate on the given event. | |
is_for_mappings_only () | |
Returns true if this definition should only be used with mappings. | |
require_data_guarantee () | |
Returns true if this definition requires a data guarantee from the cache stores being used. | |
require_locking () | |
Returns true if this definition requires locking functionality. | |
require_locking_before_write () | |
Returns true if this definition requires a lock to be aquired before a write is attempted. | |
require_multiple_identifiers () | |
Returns true if this definition requires that the cache stores support multiple identifiers. | |
require_searchable () | |
Returns true if this definition requires a searchable cache. | |
set_identifiers (array $identifiers=array()) | |
Sets the identifiers for this definition, or updates them if they have already been set. | |
should_be_persistent () | |
Please call cache_definition::use_static_acceleration() instead. | |
use_static_acceleration () | |
Returns true if we should hold onto the data flowing through the cache. | |
uses_simple_data () | |
Returns true if the data is known to be scalar or array of scalar. | |
uses_simple_keys () | |
Returns true if this definition is using simple keys. | |
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. | |
static | load_adhoc ($mode, $component, $area, array $options=array()) |
Creates an ah-hoc cache definition given the required params. | |
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. | |
const | SHARING_DEFAULTOPTIONS = 15 |
The default sharing options available. | |
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. | |
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. | |
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. | |
int | $mode |
The mode for the defintion. | |
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. | |
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. | |
bool | $requirelockingbeforewrite = false |
Gets set to true if this definition requires a lock to be acquired before a write is attempted. | |
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. | |
int | $selectedsharingoption = self::SHARING_DEFAULT |
The selected sharing option. | |
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. | |
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. | |
string | $userinputsharingkey = '' |
The user input key to use if the SHARING_INPUT option has been selected. | |
The cache definition class.
Cache definitions need to be defined in db/caches.php files. They can be constructed with the following options.
Required settings:
Optional settings:
For examples take a look at lib/db/caches.php
cache_definition::can_use_localstore | ( | ) |
Returns true if this definition allows local storage to be used for caching.
bool |
cache_definition::generate_definition_hash | ( | ) |
Generates a hash of this definition and returns it.
string |
cache_definition::generate_multi_key_parts | ( | ) |
Generates a multi key prefix for this definition.
array |
cache_definition::generate_single_key_prefix | ( | ) |
Generates a single key prefix for this definition.
string |
cache_definition::get_area | ( | ) |
Returns the area this definition is associated with.
string |
cache_definition::get_cache_class | ( | ) |
Returns the cache loader class that should be used for this definition.
string |
|
protected |
Returns a cache identification string.
string | A string to be used as part of keys. |
cache_definition::get_component | ( | ) |
Returns the component this definition is associated with.
string |
cache_definition::get_data_source | ( | ) |
Returns an instance of the data source class used for this definition.
cache_data_source |
coding_exception |
cache_definition::get_id | ( | ) |
Returns the id of this definition.
string |
cache_definition::get_identifiers | ( | ) |
Returns the identifiers that are being used for this definition.
array |
cache_definition::get_invalidation_events | ( | ) |
Returns all of the invalidation events for this definition.
array |
cache_definition::get_maxsize | ( | ) |
Returns the maximum number of items allowed in this cache.
int |
cache_definition::get_mode | ( | ) |
Returns the mode of this definition.
int | One more cache_store\MODE_ |
cache_definition::get_name | ( | ) |
Returns the name for this definition.
string |
cache_definition::get_persistent_max_size | ( | ) |
Please call cache_definition::get_static_acceleration_size() instead.
cache_definition::get_requirements_bin | ( | ) |
Returns the requirements of this definition as a binary flag.
int |
cache_definition::get_selected_sharing_option | ( | ) |
Returns the user selected sharing option for this definition.
int |
cache_definition::get_sharing_options | ( | ) |
Returns the possible sharing options that can be used with this defintion.
int |
cache_definition::get_static_acceleration_size | ( | ) |
Returns the max size for the static acceleration array.
int |
cache_definition::get_ttl | ( | ) |
Returns the ttl in seconds for this definition if there is one, or null if not.
int|null |
cache_definition::get_user_input_sharing_key | ( | ) |
Returns the user entered sharing key for this definition.
string |
cache_definition::has_data_source | ( | ) |
Returns true if this definition has an associated data source.
bool |
cache_definition::has_invalidation_events | ( | ) |
Check if the definition has any invalidation events.
bool | True if it does, false otherwise |
cache_definition::has_required_identifiers | ( | ) |
Returns true if this definition requires identifiers.
bool |
cache_definition::invalidates_on_event | ( | $event | ) |
Check if this definition should invalidate on the given event.
string | $event |
bool | True if the definition should invalidate on the event. False otherwise. |
cache_definition::is_for_mappings_only | ( | ) |
Returns true if this definition should only be used with mappings.
bool |
|
static |
Creates a cache definition given a definition from the cache configuration or from a caches.php file.
string | $id | |
array | $definition | |
string | $unused | Used to be datasourceaggregate but that was removed and this is now unused. |
cache_definition |
coding_exception |
|
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.
int | $mode | One of cache_store\MODE_* |
string | $component | The component this definition relates to. |
string | $area | The area this definition relates to. |
array | $options | An array of options, available options are:
|
cache_application|cache_session|cache_request |
cache_definition::require_data_guarantee | ( | ) |
Returns true if this definition requires a data guarantee from the cache stores being used.
bool |
cache_definition::require_locking | ( | ) |
Returns true if this definition requires locking functionality.
Either read or write locking.
bool |
cache_definition::require_locking_before_write | ( | ) |
Returns true if this definition requires a lock to be aquired before a write is attempted.
bool |
cache_definition::require_multiple_identifiers | ( | ) |
Returns true if this definition requires that the cache stores support multiple identifiers.
bool |
cache_definition::require_searchable | ( | ) |
cache_definition::set_identifiers | ( | array | $identifiers = array() | ) |
Sets the identifiers for this definition, or updates them if they have already been set.
array | $identifiers |
bool | false if no identifiers where changed, true otherwise. |
coding_exception |
cache_definition::should_be_persistent | ( | ) |
Please call cache_definition::use_static_acceleration() instead.
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.
bool |
cache_definition::uses_simple_data | ( | ) |
Returns true if the data is known to be scalar or array of scalar.
bool |
cache_definition::uses_simple_keys | ( | ) |
Returns true if this definition is using simple keys.
Simple keys contain only a-zA-Z0-9_
bool |
|
protected |
The file in which the data source class exists.
This will be included if required.
|
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.
|
protected |
The mode for the defintion.
One of cache_store\MODE_*
|
protected |
The file in which the override class exists.
This will be included if required. Absolute path
|
protected |
If set to true then we know that this definition requires the locking functionality.
This gets set during construction based upon the setting requirelockingbeforewrite.
|
protected |
Gets set to true if this definition requires searchable stores.
|
protected |
The selected sharing option.
One of self\SHARING_*
|
protected |
If set to true we know the keys are simple.
a-zA-Z0-9_
|
protected |
The TTL for data in this cache.
Please don't use this, instead use event driven invalidation.
|
protected |
The user input key to use if the SHARING_INPUT option has been selected.
Must be ALPHANUMEXT
const cache_definition::SHARING_DEFAULT = 2 |
The default sharing option that gets used if none have been selected.
SiteID. It is the most restrictive.
const cache_definition::SHARING_DEFAULTOPTIONS = 15 |
The default sharing options available.
All + SiteID + Version + Input.