Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

(no description)

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

Defines 1 class

cache_item:: (8 methods):
  __construct()
  get_key()
  get()
  is_hit()
  set()
  expires_at()
  expires_after()
  current_time()


Class: cache_item  - X-Ref

Class to define an interface for interacting with objects inside a cache.

__construct(string $key, string $module, ?int $ttl = null)   X-Ref
Constructor for the cache_item to get the key and module to retrieve or set the cache item.

param: string $key The key for the current cache item.
param: string $module determines the location of the cache item.
param: int|null $ttl Time to live for the cache item.

get_key()   X-Ref
Returns the key for the current cache item.

The key is loaded by the Implementing Library, but should be available to
the higher level callers when needed.

return: string The key string for this cache item.

get()   X-Ref
Retrieves the value of the item from the cache associated with this object's key.

The value returned must be identical to the value originally stored by set().

If isHit() returns false, this method MUST return null. Note that null
is a legitimate cache value, so the isHit() method SHOULD be used to
differentiate between "null value was found" and "no value was found."

return: mixed The value corresponding to this cache item's key, or null if not found.

is_hit()   X-Ref
Confirms if the cache item lookup resulted in a cache hit.

Note: This method MUST NOT have a race condition between calling isHit()
and calling get().

return: bool True if the request resulted in a cache hit. False otherwise.

set($value)   X-Ref
Sets the value represented by this cache item.

The $value argument may be any item that can be serialized by PHP,
although the method of serialization is left up to the Implementing
Library.

param: mixed $value The serializable value to be stored.
return: static The invoked object.

expires_at($expiration)   X-Ref
Sets the absolute expiration time for this cache item.

param: \DateTimeInterface|null $expiration
return: static The called object.

expires_after($time)   X-Ref
Sets the relative expiration time for this cache item.

param: int|\DateInterval|null $time
return: static The called object.

current_time()   X-Ref
Gets the current time in the user timezone.

return: \DateTime