Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
cache_is_key_aware Interface Reference

Cache store feature: key awareness. More...

Inheritance diagram for cache_is_key_aware:
cachestore_apcu cachestore_file cachestore_redis cachestore_session cachestore_static

Public Member Functions

 has ($key)
 Test is a cache has a key.
 
 has_all (array $keys)
 Test is a cache has all of the given keys.
 
 has_any (array $keys)
 Test if a cache has at least one of the given keys.
 

Detailed Description

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.

Member Function Documentation

◆ has()

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:

  1. Attempt to retrieve the information.
  2. Generate the information.
  3. Attempt to set the information

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.

Parameters
string | int$key
Return values
boolTrue if the cache has the requested key, false otherwise.

Implemented in cachestore_apcu, cachestore_file, cachestore_redis, cachestore_session, and cachestore_static.

◆ has_all()

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.

Parameters
array$keys
Return values
boolTrue if the cache has all of the given keys, false otherwise.

Implemented in cachestore_apcu, cachestore_file, cachestore_redis, cachestore_session, and cachestore_static.

◆ has_any()

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.

Parameters
array$keys
Return values
boolTrue if the cache has at least one of the given keys

Implemented in cachestore_apcu, cachestore_file, cachestore_redis, cachestore_session, and cachestore_static.


The documentation for this interface was generated from the following file: