Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]
The library file for the file cache store. This file is part of the file cache store, it contains the API for interacting with an instance of the store. This is used as a default cache store within the Cache API. It should never be deleted.
Copyright: | 2012 Sam Hemelryk |
License: | http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
File Size: | 927 lines (31 kb) |
Included or required: | 0 times |
Referenced: | 1 time |
Includes or requires: | 0 files |
cachestore_file:: (39 methods):
__construct()
instance_created()
is_ready()
is_initialised()
get_supported_features()
supports_multiple_identifiers()
get_supported_modes()
are_requirements_met()
is_supported_mode()
initialise()
prescan_keys()
glob_keys_pattern()
file_path_for_key()
get()
get_many()
get_last_io_bytes()
delete()
delete_many()
set()
prep_data_before_save()
prep_data_after_read()
set_many()
has()
has_all()
has_any()
purge()
purge_all_definitions()
config_get_configuration_array()
config_set_edit_form_data()
ensure_path_exists()
instance_deleted()
initialise_test_instance()
unit_test_configuration()
write_file()
my_name()
find_all()
find_by_prefix()
store_total_size()
cache_size_details()
Class: cachestore_file - X-Ref
The file store class.__construct($name, array $configuration = array() X-Ref |
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. param: string $name param: array $configuration |
instance_created() X-Ref |
Performs any necessary operation when the file store instance has been created. |
is_ready() X-Ref |
Returns true if this store instance is ready to be used. return: bool |
is_initialised() X-Ref |
Returns true once this instance has been initialised. return: bool |
get_supported_features(array $configuration = array() X-Ref |
Returns the supported features as a combined int. return: int param: array $configuration |
supports_multiple_identifiers() X-Ref |
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.) return: bool False |
get_supported_modes(array $configuration = array() X-Ref |
Returns the supported modes as a combined int. return: int param: array $configuration |
are_requirements_met() X-Ref |
Returns true if the store requirements are met. return: bool |
is_supported_mode($mode) X-Ref |
Returns true if the given mode is supported by this store. return: bool param: int $mode One of cache_store::MODE_* |
initialise(cache_definition $definition) X-Ref |
Initialises the cache. Once this has been done the cache is all set to be used. param: cache_definition $definition |
prescan_keys() X-Ref |
Pre-scan the cache to see which keys are present. |
glob_keys_pattern($prefix = '') X-Ref |
Gets a pattern suitable for use with glob to find all keys in the cache. return: string The pattern. param: string $prefix A prefix to use. |
file_path_for_key($key, $create = false) X-Ref |
Returns the file path to use for the given key. return: string The full path to the file that stores a particular cache key. param: string $key The key to generate a file path for. param: bool $create If set to the true the directory structure the key requires will be created. |
get($key) X-Ref |
Retrieves an item from the cache store given its key. return: mixed The data that was associated with the key, or false if the key did not exist. param: string $key The key to retrieve |
get_many($keys) X-Ref |
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. return: array An array of items from the cache. There will be an item for each key, those that were not in the store will param: array $keys The array of keys to retrieve |
get_last_io_bytes() X-Ref |
Gets bytes read by last get() or get_many(), or written by set() or set_many(). return: int Bytes read or written |
delete($key) X-Ref |
Deletes an item from the cache store. return: bool Returns true if the operation was a success, false otherwise. param: string $key The key to delete. |
delete_many(array $keys) X-Ref |
Deletes several keys from the cache in a single action. return: int The number of items successfully deleted. param: array $keys The keys to delete |
set($key, $data) X-Ref |
Sets an item in the cache given its key and data value. return: bool True if the operation was a success false otherwise. param: string $key The key to use. param: mixed $data The data to set. |
prep_data_before_save($data) X-Ref |
Prepares data to be stored in a file. return: string param: mixed $data |
prep_data_after_read($data) X-Ref |
Prepares the data it has been read from the cache. Undoing what was done in prep_data_before_save. return: mixed param: string $data |
set_many(array $keyvaluearray) X-Ref |
Sets many items in the cache in a single transaction. return: int The number of items successfully set. It is up to the developer to check this matches the number of items param: array $keyvaluearray An array of key value pairs. Each item in the array will be an associative array with two |
has($key) X-Ref |
Checks if the store has a record for the given key and returns true if so. return: bool param: string $key |
has_all(array $keys) X-Ref |
Returns true if the store contains records for all of the given keys. return: bool param: array $keys |
has_any(array $keys) X-Ref |
Returns true if the store contains records for any of the given keys. return: bool param: array $keys |
purge() X-Ref |
Purges the cache definition deleting all the items within it. return: boolean True on success. False otherwise. |
purge_all_definitions() X-Ref |
Purges all the cache definitions deleting all items within them. return: boolean True on success. False otherwise. |
config_get_configuration_array($data) X-Ref |
Given the data from the add instance form this function creates a configuration array. return: array param: stdClass $data |
config_set_edit_form_data(moodleform $editform, array $config) X-Ref |
Allows the cache store to set its data against the edit form before it is shown to the user. param: moodleform $editform param: array $config |
ensure_path_exists() X-Ref |
Checks to make sure that the path for the file cache exists. return: bool |
instance_deleted() X-Ref |
Performs any necessary clean up when the file store instance is being deleted. 1. Purges the cache directory. 2. Deletes the directory we created for the given definition. |
initialise_test_instance(cache_definition $definition) X-Ref |
Generates an instance of the cache store that can be used for testing. Returns an instance of the cache store, or false if one cannot be created. return: cachestore_file param: cache_definition $definition |
unit_test_configuration() X-Ref |
Generates the appropriate configuration required for unit testing. return: array Array of unit test configuration data to be used by initialise(). |
write_file($file, $content) X-Ref |
Writes your madness to a file. There are several things going on in this function to try to ensure what we don't end up with partial writes etc. 1. Files for writing are opened with the mode xb, the file must be created and can not already exist. 2. Renaming, data is written to a temporary file, where it can be verified using md5 and is then renamed. return: bool param: string $file Absolute file path param: string $content The content to write. |
my_name() X-Ref |
Returns the name of this instance. return: string |
find_all() X-Ref |
Finds all of the keys being used by this cache store instance. return: array |
find_by_prefix($prefix) X-Ref |
Finds all of the keys whose keys start with the given prefix. param: string $prefix |
store_total_size() X-Ref |
Gets total size for the directory used by the cache store. return: int Total size in bytes |
cache_size_details(int $samplekeys = 50) X-Ref |
Gets total size for a specific cache. With the file cache we can just look at the directory listing without having to actually load any files, so the $samplekeys parameter is ignored. return: stdClass Cache details param: int $samplekeys Unused |