Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
The Session store class. More...
Public Member Functions | |
__construct ($name, array $configuration=array()) | |
Constructs the store instance. More... | |
cleanup () | |
create_clone (array $details=array()) | |
Creates a clone of this store instance ready to be initialised. More... | |
delete ($key) | |
Deletes an item from the cache store. More... | |
delete_many (array $keys) | |
Deletes several keys from the cache in a single action. More... | |
find_all () | |
Finds all of the keys being stored in the cache store instance. More... | |
find_by_prefix ($prefix) | |
Finds all of the keys whose keys start with the given prefix. More... | |
get ($key) | |
Retrieves an item from the cache store given its key. More... | |
get_many ($keys) | |
Retrieves several items from the cache store in a single transaction. More... | |
get_warnings () | |
Can be overridden to return any warnings this store instance should make to the admin. More... | |
has ($key) | |
Checks if the store has a record for the given key and returns true if so. More... | |
has_all (array $keys) | |
Returns true if the store contains records for all of the given keys. More... | |
has_any (array $keys) | |
Returns true if the store contains records for any of the given keys. More... | |
initialise (cache_definition $definition) | |
Initialises the cache. More... | |
instance_created () | |
Performs any necessary operation when the store instance has been created. More... | |
instance_deleted () | |
Performs any necessary clean up when the store instance is being deleted. | |
is_initialised () | |
Returns true once this instance has been initialised. More... | |
is_ready () | |
Returns true if this cache store instance is ready to use. More... | |
is_searchable () | |
Returns true if the store instance is searchable. More... | |
my_name () | |
Returns the name of this instance. More... | |
purge () | |
Purges the cache deleting all items within it. More... | |
set ($key, $data) | |
Sets an item in the cache given its key and data value. More... | |
set ($key, $data, $testmaxsize=true) | |
Sets an item in the cache given its key and data value. More... | |
set_many (array $keyvaluearray) | |
Sets many items in the cache in a single transaction. More... | |
store_supports_native_ttl () | |
This store supports native TTL handling. More... | |
supports_data_guarantee () | |
Returns true if the store instance guarantees data. More... | |
supports_dereferencing_objects () | |
Returns true if the store automatically dereferences objects. More... | |
supports_multiple_identifiers () | |
Returns false as this store does not support multiple identifiers. More... | |
supports_native_ttl () | |
Returns true if the store instance supports native ttl. More... | |
Static Public Member Functions | |
static | are_requirements_met () |
Returns true if the store requirements are met. More... | |
static | can_add_instance () |
Returns true if the user can add an instance of the store plugin. More... | |
static | get_supported_features (array $configuration=array()) |
Returns the supported features as a combined int. More... | |
static | get_supported_modes (array $configuration=array()) |
Returns the supported modes as a combined int. More... | |
static | initialise_test_instance (cache_definition $definition) |
Generates an instance of the cache store that can be used for testing. More... | |
static | is_supported_mode ($mode) |
Returns true if the given mode is supported by this store. More... | |
static | ready_to_be_used_for_testing () |
Returns true if this cache store instance is both suitable for testing, and ready for testing. More... | |
static | unit_test_configuration () |
Generates the appropriate configuration required for unit testing. More... | |
Public Attributes | |
const | DEREFERENCES_OBJECTS = 16 |
The cache store dereferences objects. More... | |
const | IS_SEARCHABLE = 8 |
The cache is searchable by key. | |
const | MODE_APPLICATION = 1 |
Application caches. More... | |
const | MODE_REQUEST = 4 |
Request caches. More... | |
const | MODE_SESSION = 2 |
Session caches. More... | |
const | SUPPORTS_DATA_GUARANTEE = 2 |
Ensures data remains in the cache once set. | |
const | SUPPORTS_MULTIPLE_IDENTIFIERS = 1 |
Supports multi-part keys. | |
const | SUPPORTS_NATIVE_TTL = 4 |
Supports a native ttl system. | |
Protected Member Functions | |
check_ttl () | |
Removes expired elements. More... | |
reduce_for_maxsize () | |
Reduces the size of the array if maxsize has been hit. More... | |
Static Protected Member Functions | |
static | flush_store () |
Flushes the store of all data. | |
static | flush_store_by_id ($id) |
Flushes the data belong to the given store id. More... | |
static & | register_store_id ($id) |
Returns a static store by reference... More... | |
Protected Attributes | |
bool int | $maxsize = false |
The maximum size for the store, or false if there isn't one. | |
store | $name |
The name of the store. | |
array | $store |
The store we use for data. | |
int | $storecount = 0 |
The number of items currently being stored. | |
string | $storeid |
The store id (should be unique) | |
int | $ttl = 0 |
The ttl if there is one. More... | |
The Session store class.
cachestore_session::__construct | ( | $name, | |
array | $configuration = array() |
||
) |
Constructs the store instance.
Noting that this function is not an initialisation. It is used to prepare the store for use. The store will be initialised when required and will be provided with a cache_definition at that time.
string | $name | |
array | $configuration |
Reimplemented from cache_store.
|
static |
Returns true if the store requirements are met.
bool |
Implements cache_store_interface.
|
static |
Returns true if the user can add an instance of the store plugin.
bool |
Reimplemented from cache_store.
|
protected |
Removes expired elements.
int | number of removed elements |
|
inherited |
|
inherited |
Creates a clone of this store instance ready to be initialised.
This method is used so that a cache store needs only be constructed once. Future requests for an instance of the store will be given a cloned instance.
If you are writing a cache store that isn't compatible with the clone operation you can override this method to handle any situations you want before cloning.
array | $details | An array containing the details of the store from the cache config. |
cache_store |
cachestore_session::delete | ( | $key | ) |
Deletes an item from the cache store.
string | $key | The key to delete. |
bool | Returns true if the operation was a success, false otherwise. |
Reimplemented from cache_store.
cachestore_session::delete_many | ( | array | $keys | ) |
Deletes several keys from the cache in a single action.
array | $keys | The keys to delete |
int | The number of items successfully deleted. |
Reimplemented from cache_store.
cachestore_session::find_all | ( | ) |
Finds all of the keys being stored in the cache store instance.
array |
Implements cache_is_searchable.
cachestore_session::find_by_prefix | ( | $prefix | ) |
Finds all of the keys whose keys start with the given prefix.
string | $prefix |
array | An array of keys. |
Implements cache_is_searchable.
|
staticprotectedinherited |
Flushes the data belong to the given store id.
string | $id |
cachestore_session::get | ( | $key | ) |
Retrieves an item from the cache store given its key.
string | $key | The key to retrieve |
mixed | The data that was associated with the key, or false if the key did not exist. |
Reimplemented from cache_store.
cachestore_session::get_many | ( | $keys | ) |
Retrieves several items from the cache store in a single transaction.
If not all of the items are available in the cache then the data value for those that are missing will be set to false.
array | $keys | The array of keys to retrieve |
array | An array of items from the cache. There will be an item for each key, those that were not in the store will be set to false. |
Reimplemented from cache_store.
|
static |
Returns the supported features as a combined int.
array | $configuration |
int |
Implements cache_store_interface.
|
static |
Returns the supported modes as a combined int.
array | $configuration |
int |
Implements cache_store_interface.
|
inherited |
Can be overridden to return any warnings this store instance should make to the admin.
This should be used to notify things like configuration conflicts etc. The warnings returned here will be displayed on the cache configuration screen.
string[] | An array of warning strings from the store instance. |
Reimplemented in cachestore_memcached.
cachestore_session::has | ( | $key | ) |
Checks if the store has a record for the given key and returns true if so.
string | $key |
bool |
Implements cache_is_key_aware.
cachestore_session::has_all | ( | array | $keys | ) |
Returns true if the store contains records for all of the given keys.
array | $keys |
bool |
Implements cache_is_key_aware.
cachestore_session::has_any | ( | array | $keys | ) |
Returns true if the store contains records for any of the given keys.
array | $keys |
bool |
Implements cache_is_key_aware.
cachestore_session::initialise | ( | cache_definition | $definition | ) |
Initialises the cache.
Once this has been done the cache is all set to be used.
cache_definition | $definition |
Reimplemented from cache_store.
|
static |
Generates an instance of the cache store that can be used for testing.
cache_definition | $definition |
cachestore_session |
Implements cache_store_interface.
|
inherited |
Performs any necessary operation when the store instance has been created.
Reimplemented in cachestore_file.
cachestore_session::is_initialised | ( | ) |
Returns true once this instance has been initialised.
bool |
Reimplemented from cache_store.
|
inherited |
Returns true if this cache store instance is ready to use.
bool |
Reimplemented in cachestore_redis, cachestore_mongodb, cachestore_memcached, and cachestore_file.
|
inherited |
Returns true if the store instance is searchable.
bool |
|
static |
Returns true if the given mode is supported by this store.
int | $mode | One of cache_store::MODE_* |
bool |
Implements cache_store_interface.
cachestore_session::my_name | ( | ) |
cachestore_session::purge | ( | ) |
Purges the cache deleting all items within it.
boolean | True on success. False otherwise. |
Reimplemented from cache_store.
|
staticinherited |
Returns true if this cache store instance is both suitable for testing, and ready for testing.
Cache stores that support being used as the default store for unit and acceptance testing should override this function and return true if there requirements have been met.
bool |
Reimplemented in cachestore_redis, cachestore_mongodb, cachestore_memcached, and cachestore_apcu.
|
protected |
Reduces the size of the array if maxsize has been hit.
This function reduces the size of the store reducing it by 10% of its maxsize. It removes the oldest items in the store when doing this. The reason it does this an doesn't use a least recently used system is purely the overhead such a system requires. The current approach is focused on speed, MUC already adds enough overhead to static/session caches and avoiding more is of benefit.
int |
|
staticprotectedinherited |
Returns a static store by reference...
REFERENCE SUPER IMPORTANT.
string | $id |
array |
|
abstractinherited |
Sets an item in the cache given its key and data value.
string | $key | The key to use. |
mixed | $data | The data to set. |
bool | True if the operation was a success false otherwise. |
Reimplemented in cachestore_redis, cachestore_mongodb, cachestore_memcached, cachestore_file, cachestore_apcu, and cachestore_dummy.
cachestore_session::set | ( | $key, | |
$data, | |||
$testmaxsize = true |
|||
) |
Sets an item in the cache given its key and data value.
string | $key | The key to use. |
mixed | $data | The data to set. |
bool | $testmaxsize | If set to true then we test the maxsize arg and reduce if required. If this is set to false you will need to perform these checks yourself. This allows for bulk set's to be performed and maxsize tests performed once. |
bool | True if the operation was a success false otherwise. |
cachestore_session::set_many | ( | array | $keyvaluearray | ) |
Sets many items in the cache in a single transaction.
array | $keyvaluearray | An array of key value pairs. Each item in the array will be an associative array with two keys, 'key' and 'value'. |
int | The number of items successfully set. It is up to the developer to check this matches the number of items sent ... if they care that is. |
Reimplemented from cache_store.
cachestore_session::store_supports_native_ttl | ( | ) |
This store supports native TTL handling.
bool |
|
inherited |
Returns true if the store instance guarantees data.
bool |
|
inherited |
Returns true if the store automatically dereferences objects.
bool |
cachestore_session::supports_multiple_identifiers | ( | ) |
Returns false as this store does not support multiple identifiers.
(This optional function is a performance optimisation; it must be consistent with the value from get_supported_features.)
bool | False |
Reimplemented from cache_store.
|
inherited |
Returns true if the store instance supports native ttl.
bool |
|
static |
Generates the appropriate configuration required for unit testing.
array | Array of unit test configuration data to be used by initialise(). |
Implements cache_store_interface.
|
protected |
The ttl if there is one.
Hopefully not.
|
inherited |
The cache store dereferences objects.
When set, loaders will assume that all data coming from this store has already had all references resolved. So even for complex object structures it will not try to remove references again.
|
inherited |
Application caches.
These are shared caches.
|
inherited |
Request caches.
Static caches really.
|
inherited |
Session caches.
Just access to the PHP session.