Moodle PHP Documentation 4.1
Moodle 4.1.11 (Build: 20240610) (c8c84b4af18)
|
The MongoDB Cache store. More...
Public Member Functions | |
__construct ($name, array $configuration=array()) | |
Constructs a new instance of the Mongo store. | |
cache_size_details (int $samplekeys=50) | |
Gets the amount of memory used by this specific cache within the store, if known. | |
cleanup () | |
create_clone (array $details=array()) | |
Creates a clone of this store instance ready to be initialised. | |
delete ($key) | |
Deletes an item from the cache store. | |
delete_many (array $keys) | |
Deletes several keys from the cache in a single action. | |
estimate_stored_size ($key, $value) | |
Estimates the storage size used within this cache if the given value is stored with the given key. | |
get ($key) | |
Retrieves an item from the cache store given its key. | |
get_last_io_bytes () | |
Gets the number of bytes read from or written to cache as a result of the last action. | |
get_many ($keys) | |
Retrieves several items from the cache store in a single transaction. | |
get_warnings () | |
Can be overridden to return any warnings this store instance should make to the admin. | |
initialise (cache_definition $definition) | |
Initialises the store instance for use. | |
instance_created () | |
Performs any necessary operation when the store instance has been created. | |
instance_deleted () | |
Performs any necessary clean up when the store instance is being deleted. | |
is_initialised () | |
Returns true if this store instance has been initialised. | |
is_ready () | |
Returns true if this store instance is ready to use. | |
is_searchable () | |
Returns true if the store instance is searchable. | |
my_name () | |
Returns the name of this instance. | |
purge () | |
Purges the cache deleting all items within it. | |
set ($key, $data) | |
Sets an item in the cache given its key and data value. | |
set_many (array $keyvaluearray) | |
Sets many items in the cache in a single transaction. | |
store_total_size () | |
Gets the amount of memory/storage currently used by this cache store if known. | |
supports_data_guarantee () | |
Returns true if the store instance guarantees data. | |
supports_dereferencing_objects () | |
Returns true if the store automatically dereferences objects. | |
supports_multiple_identifiers () | |
Returns true if this store is making use of multiple identifiers. | |
supports_native_ttl () | |
Returns true if the store instance supports native ttl. | |
Static Public Member Functions | |
static | are_requirements_met () |
Returns true if the requirements of this store have been met. | |
static | can_add_instance () |
Returns true if the user can add an instance of the store plugin. | |
static | config_get_configuration_array ($data) |
Takes the object from the add instance store and creates a configuration array that can be used to initialise an instance. | |
static | config_set_edit_form_data (moodleform $editform, array $config) |
Allows the cache store to set its data against the edit form before it is shown to the user. | |
static | get_supported_features (array $configuration=array()) |
Returns the supported features. | |
static | get_supported_modes (array $configuration=array()) |
Returns an int describing the supported modes. | |
static | initialise_test_instance (cache_definition $definition) |
Generates an instance of the cache store that can be used for testing. | |
static | is_supported_mode ($mode) |
Returns true if the given mode is supported by this store. | |
static | ready_to_be_used_for_testing () |
Returns true if this cache store instance is both suitable for testing, and ready for testing. | |
static | unit_test_configuration () |
Generates an instance of the cache store that can be used for testing. | |
Public Attributes | |
const | DEREFERENCES_OBJECTS = 16 |
The cache store dereferences objects. | |
const | IO_BYTES_NOT_SUPPORTED = -1 |
Returned from get_last_io_bytes if this cache store doesn't support counting bytes read/sent. | |
const | IS_SEARCHABLE = 8 |
The cache is searchable by key. | |
const | MODE_APPLICATION = 1 |
Application caches. | |
const | MODE_REQUEST = 4 |
Request caches. | |
const | MODE_SESSION = 2 |
Session caches. | |
const | STATIC_ACCEL = '** static accel. **' |
Static caches. | |
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 Attributes | |
MongoDB Collection | $collection |
The Collection object. | |
MongoDB Client | $connection = false |
The Connection object. | |
MongoDB Database | $database |
The Database Object. | |
string | $databasename = 'mcache' |
The name of the database to use. | |
string | $definitionhash = null |
The definition has which is used in the construction of the collection. | |
bool | $extendedmode = false |
If set to true then multiple identifiers will be requested and used. | |
bool | $isready = false |
Set to true once this store is ready to be initialised and used. | |
string | $name |
The name of the store. | |
array | $options = array() |
The database connection options. | |
string | $server = 'mongodb://127.0.0.1:27017' |
The server connection string. | |
bool int | $usesafe = true |
Determines if and what safe setting is to be used. | |
The MongoDB Cache store.
This cache store uses the MongoDB Native Driver and the MongoDB PHP Library. For installation instructions have a look at the following two links:
cachestore_mongodb::__construct | ( | $name, | |
array | $configuration = array() ) |
Constructs a new instance of the Mongo store.
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 requirements of this store have been met.
bool |
Implements cache_store_interface.
|
inherited |
Gets the amount of memory used by this specific cache within the store, if known.
This function may be slow and should not be called in normal usage, only for administration pages. The value is usually an estimate, and may not be available at all.
When estimating, a number of sample items will be used for the estimate. If set to 50 (default), then this function will retrieve 50 random items and use that to estimate the total size.
The return value has the following fields:
int | $samplekeys | Number of samples to use |
stdClass | Object with information about the store size |
Reimplemented in cachestore_file.
|
staticinherited |
Returns true if the user can add an instance of the store plugin.
bool |
Reimplemented in cachestore_dummy, cachestore_session, and cachestore_static.
|
inherited |
|
static |
Takes the object from the add instance store and creates a configuration array that can be used to initialise an instance.
stdClass | $data |
array |
Implements cache_is_configurable.
|
static |
Allows the cache store to set its data against the edit form before it is shown to the user.
moodleform | $editform | |
array | $config |
Implements cache_is_configurable.
|
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_mongodb::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_mongodb::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.
|
inherited |
Estimates the storage size used within this cache if the given value is stored with the given key.
This function is not exactly accurate; it does not necessarily take into account all the overheads involved. It is only intended to give a good idea of the relative size of different caches.
The default implementation serializes both key and value and sums the lengths (as a rough estimate which is probably good enough for everything unless the cache offers compression).
mixed | $key | Key |
mixed | $value | Value |
int | Size in bytes |
Reimplemented in cachestore_redis.
cachestore_mongodb::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.
|
inherited |
Gets the number of bytes read from or written to cache as a result of the last action.
This includes calls to the functions get(), get_many(), set(), and set_many(). The number is reset by calling any of these functions.
This should be the actual number of bytes of the value read from or written to cache, giving an impression of the network or other load. It will not be exactly the same amount as netowrk traffic because of protocol overhead, key text, etc.
If not supported, returns IO_BYTES_NOT_SUPPORTED.
int | Bytes read (or 0 if none/not supported) |
Reimplemented in cachestore_file, and cachestore_redis.
cachestore_mongodb::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. |
Reimplemented from cache_store.
|
static |
Returns the supported features.
array | $configuration |
int |
Implements cache_store_interface.
|
static |
Returns an int describing the supported modes.
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_mongodb::initialise | ( | cache_definition | $definition | ) |
Initialises the store instance for use.
Once this has been done the cache is all set to be used.
cache_definition | $definition |
coding_exception |
Reimplemented from cache_store.
|
static |
Generates an instance of the cache store that can be used for testing.
cache_definition | $definition |
false |
Implements cache_store_interface.
|
inherited |
Performs any necessary operation when the store instance has been created.
Reimplemented in cachestore_file.
cachestore_mongodb::instance_deleted | ( | ) |
Performs any necessary clean up when the store instance is being deleted.
Reimplemented from cache_store.
cachestore_mongodb::is_initialised | ( | ) |
Returns true if this store instance has been initialised.
bool |
Reimplemented from cache_store.
cachestore_mongodb::is_ready | ( | ) |
Returns true if this store instance is ready to use.
bool |
Reimplemented from cache_store.
|
inherited |
Returns true if the store instance is searchable.
bool |
|
static |
Returns true if the given mode is supported by this store.
int | $mode |
bool |
Implements cache_store_interface.
cachestore_mongodb::my_name | ( | ) |
cachestore_mongodb::purge | ( | ) |
Purges the cache deleting all items within it.
boolean | True on success. False otherwise. |
Reimplemented from cache_store.
|
static |
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 from cache_store.
cachestore_mongodb::set | ( | $key, | |
$data ) |
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 from cache_store.
cachestore_mongodb::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.
|
inherited |
Gets the amount of memory/storage currently used by this cache store if known.
This value should be obtained quickly from the store itself, if available.
This is the total memory usage of the entire store, not for ther specific cache in question.
Where not supported (default), will always return null.
int|null | Amount of memory used in bytes or null |
Reimplemented in cachestore_file, and cachestore_redis.
|
inherited |
Returns true if the store instance guarantees data.
bool |
|
inherited |
Returns true if the store automatically dereferences objects.
bool |
cachestore_mongodb::supports_multiple_identifiers | ( | ) |
Returns true if this store is making use of multiple identifiers.
bool |
Reimplemented from cache_store.
|
inherited |
Returns true if the store instance supports native ttl.
bool |
|
static |
Generates an instance of the cache store that can be used for testing.
cache_definition | $definition |
false |
Implements cache_store_interface.
|
protected |
The server connection string.
Comma separated values.
|
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.