Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

(no description)

File Size: 114 lines (5 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

CacheInterface:: (8 methods):
  get()
  set()
  delete()
  clear()
  getMultiple()
  setMultiple()
  deleteMultiple()
  has()


Interface: CacheInterface  - X-Ref

get($key, $default = null)   X-Ref
Fetches a value from the cache.

param: string $key     The unique key of this item in the cache.
param: mixed  $default Default value to return if the key does not exist.
return: mixed The value of the item from the cache, or $default in case of cache miss.

set($key, $value, $ttl = null)   X-Ref
Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.

param: string                 $key   The key of the item to store.
param: mixed                  $value The value of the item to store, must be serializable.
param: null|int|\DateInterval $ttl   Optional. The TTL value of this item. If no value is sent and
return: bool True on success and false on failure.

delete($key)   X-Ref
Delete an item from the cache by its unique key.

param: string $key The unique cache key of the item to delete.
return: bool True if the item was successfully removed. False if there was an error.

clear()   X-Ref
Wipes clean the entire cache's keys.

return: bool True on success and false on failure.

getMultiple($keys, $default = null)   X-Ref
Obtains multiple cache items by their unique keys.

param: iterable $keys    A list of keys that can obtained in a single operation.
param: mixed    $default Default value to return for keys that do not exist.
return: iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.

setMultiple($values, $ttl = null)   X-Ref
Persists a set of key => value pairs in the cache, with an optional TTL.

param: iterable               $values A list of key => value pairs for a multiple-set operation.
param: null|int|\DateInterval $ttl    Optional. The TTL value of this item. If no value is sent and
return: bool True on success and false on failure.

deleteMultiple($keys)   X-Ref
Deletes multiple cache items in a single operation.

param: iterable $keys A list of string-based keys to be deleted.
return: bool True if the items were successfully removed. False if there was an error.

has($key)   X-Ref
Determines whether an item is present in the cache.

NOTE: It is recommended that has() is only to be used for cache warming type purposes
and not to be used within your live applications operations for get/set, as this method
is subject to a race condition where your has() will return true and immediately after,
another script can remove it making the state of your app out of date.

param: string $key The cache item key.
return: bool