Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
Psr16 Class Reference

Caches data into a PSR-16 cache implementation. More...

Inheritance diagram for Psr16:

Public Member Functions

 __construct (CacheInterface $cache)
 PSR-16 cache implementation.
 
 delete_data (string $key)
 Delete an item from the cache by its unique key.
 
 get_data (string $key, $default=null)
 Fetches a value from the cache.
 
 set_data (string $key, array $value, ?int $ttl=null)
 Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
 

Detailed Description

Caches data into a PSR-16 cache implementation.

@subpackage Caching

Constructor & Destructor Documentation

◆ __construct()

Psr16::__construct ( CacheInterface $cache)

PSR-16 cache implementation.

Parameters
CacheInterface$cache

Member Function Documentation

◆ delete_data()

Psr16::delete_data ( string $key)

Delete an item from the cache by its unique key.

Equivalent to Psr\SimpleCache\CacheInterface\delete() public function delete(string $key): bool;

Parameters
string$keyThe unique cache key of the item to delete.
Return values
boolTrue if the item was successfully removed. False if there was an error.
Exceptions
InvalidArgumentExceptionMUST be thrown if the $key string is not a legal value.

◆ get_data()

Psr16::get_data ( string $key,
$default = null )

Fetches a value from the cache.

Equivalent to Psr\SimpleCache\CacheInterface\get() public function get(string $key, mixed $default = null): mixed;

Parameters
string$keyThe unique key of this item in the cache.
mixed$defaultDefault value to return if the key does not exist.
Return values
array|mixedThe value of the item from the cache, or $default in case of cache miss.
Exceptions
InvalidArgumentExceptionMUST be thrown if the $key string is not a legal value.

◆ set_data()

Psr16::set_data ( string $key,
array $value,
?int $ttl = null )

Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.

Equivalent to Psr\SimpleCache\CacheInterface\set() public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool;

Parameters
string$keyThe key of the item to store.
array$valueThe value of the item to store, must be serializable.
null | int$ttlOptional. The TTL value of this item. If no value is sent and the driver supports TTL then the library may set a default value for it or let the driver take care of that.
Return values
boolTrue on success and false on failure.
Exceptions
InvalidArgumentExceptionMUST be thrown if the $key string is not a legal value.

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