Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
Cache store feature: key awareness. More...
Public Member Functions | |
has ($key) | |
Test is a cache has a key. More... | |
has_all (array $keys) | |
Test is a cache has all of the given keys. More... | |
has_any (array $keys) | |
Test if a cache has at least one of the given keys. More... | |
Cache store feature: key awareness.
This is a feature that cache stores and cache loaders can both choose to implement. If a cache store implements this then it will be made responsible for tests for items within the cache. If the cache store being used doesn't implement this then it will be the responsibility of the cache loader to use the equivalent get methods to mimick the functionality of these tests.
Cache stores should only override these methods if they natively support such features or if they have a better performing means of performing these tests than the handling that would otherwise take place in the cache_loader.
Can be implemented by classes already implementing cache_store.
cache_is_key_aware::has | ( | $key | ) |
Test is a cache has a key.
The use of the has methods is strongly discouraged. In a high load environment the cache may well change between the test and any subsequent action (get, set, delete etc). Instead it is recommended to write your code in such a way they it performs the following steps:
Its also worth mentioning that not all stores support key tests. For stores that don't support key tests this functionality is mimicked by using the equivalent get method. Just one more reason you should not use these methods unless you have a very good reason to do so.
string | int | $key |
bool | True if the cache has the requested key, false otherwise. |
Implemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_file, and cachestore_apcu.
cache_is_key_aware::has_all | ( | array | $keys | ) |
Test is a cache has all of the given keys.
It is strongly recommended to avoid the use of this function if not absolutely required. In a high load environment the cache may well change between the test and any subsequent action (get, set, delete etc).
Its also worth mentioning that not all stores support key tests. For stores that don't support key tests this functionality is mimicked by using the equivalent get method. Just one more reason you should not use these methods unless you have a very good reason to do so.
array | $keys |
bool | True if the cache has all of the given keys, false otherwise. |
Implemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_file, and cachestore_apcu.
cache_is_key_aware::has_any | ( | array | $keys | ) |
Test if a cache has at least one of the given keys.
It is strongly recommended to avoid the use of this function if not absolutely required. In a high load environment the cache may well change between the test and any subsequent action (get, set, delete etc).
Its also worth mentioning that not all stores support key tests. For stores that don't support key tests this functionality is mimicked by using the equivalent get method. Just one more reason you should not use these methods unless you have a very good reason to do so.
array | $keys |
bool | True if the cache has at least one of the given keys |
Implemented in cachestore_static, cachestore_session, cachestore_redis, cachestore_file, and cachestore_apcu.