cache_support
class cache_support
| internal |
Cache utility wrapper for Moodle's Cache API.
This class centralizes access to Moodle cache to protect the codebase from future architectural changes. All interactions with cache should go through this class to provide a stable, safe API layer.
Constants
| PLUGIN_NAME |
|
| DEFAULT_CACHE |
|
Methods
Creates a Moodle cache loader instance for the given area.
Resolves a value via callback and stores it in cache if missing.
Retrieves a value from the cache.
Stores a value into the cache.
Checks if a key exists in the cache.
Deletes a key from the cache.
Deletes multiple keys from the cache at once.
Fetches multiple keys from the cache in a single call.
Stores multiple key/value pairs into the cache.
Purges all entries in the given cache area.
Details
at line 49
static cache|null
make(string|null $area = null)
Creates a Moodle cache loader instance for the given area.
at line 76
static mixed
get_or_set(string $key, callable $resolver, string $area = self::DEFAULT_CACHE)
Resolves a value via callback and stores it in cache if missing.
This method simplifies the common pattern of reading from cache and, if missing, resolving the value via callback and storing it.
Note: Moodle Cache API does not support per-item TTL at this level; if you need expiration control, use definitions in db/caches.php or invalidation mechanics via keys/versions.
at line 109
static mixed
get(string $key, string $area = self::DEFAULT_CACHE)
Retrieves a value from the cache.
at line 134
static bool
set(string $key, mixed $value, string $area = self::DEFAULT_CACHE)
Stores a value into the cache.
at line 158
static bool
has(string $key, string $area = self::DEFAULT_CACHE)
Checks if a key exists in the cache.
at line 182
static bool
delete(string $key, string $area = self::DEFAULT_CACHE)
Deletes a key from the cache.
at line 206
static bool
delete_many(array $keys, string $area = self::DEFAULT_CACHE)
Deletes multiple keys from the cache at once.
at line 231
static array|false
get_many(array $keys, string $area = self::DEFAULT_CACHE)
Fetches multiple keys from the cache in a single call.
at line 255
static bool
set_many(array $keyvalues, string $area = self::DEFAULT_CACHE)
Stores multiple key/value pairs into the cache.
at line 279
static bool
purge(string $area = self::DEFAULT_CACHE)
Purges all entries in the given cache area.