Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
/cache/ -> lib.php (source)

The core cache API. Pretty much just includes the mandatory classes and contains the misc classes that arn't worth separating into individual files.

Copyright: 2012 Sam Hemelryk
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 228 lines (7 kb)
Included or required: 1 time
Referenced: 4 times
Includes or requires: 0 files

Defines 4 classes

cache_cached_object:: (2 methods):
  __construct()
  restore_object()

cache_ttl_wrapper:: (2 methods):
  __construct()
  has_expired()

cache_exception:: (1 method):
  __construct()

cacheable_object_array:: (3 methods):
  __construct()
  prepare_to_cache()
  wake_from_cache()


Class: cache_cached_object  - X-Ref

A cached object wrapper.

This class gets used when the data is an object that has implemented the cacheable_object interface.

__construct(cacheable_object $obj)   X-Ref
Constructs a cached object wrapper.

param: cacheable_object $obj

restore_object()   X-Ref
Restores the data as an instance of the cacheable_object class.

return: object

Class: cache_ttl_wrapper  - X-Ref

A wrapper class used to handle ttl when the cache store doesn't natively support it.

This class is exactly why you should use event driving invalidation of cache data rather than relying on ttl.

__construct($data, $ttl)   X-Ref
Constructs a ttl cache wrapper.

param: mixed $data
param: int $ttl The time to live in seconds.

has_expired()   X-Ref
Returns true if the data has expired.

return: int

Class: cache_exception  - X-Ref

A cache exception class. Just allows people to catch cache exceptions.

__construct($errorcode, $module = 'cache', $link = '', $a = null, $debuginfo = null)   X-Ref
Constructs a new exception

param: string $errorcode
param: string $module
param: string $link
param: mixed $a
param: mixed $debuginfo

Class: cacheable_object_array  - X-Ref

An array of cacheable objects.

This class allows a developer to create an array of cacheable objects and store that.
The cache API doesn't check items within an array to see whether they are cacheable. Such a check would be very costly to both
arrays using cacheable object and those that don't.
Instead the developer must explicitly use a cacheable_object_array instance.

The following is one example of how this class can be used.
<code>
$data = array();
$data[] = new cacheable_object('one');
$data[] = new cacheable_object('two');
$data[] = new cacheable_object('three');
$cache->set(new cacheable_object_array($data));
</code>
Another example would be
<code>
$data = new cacheable_object_array();
$data[] = new cacheable_object('one');
$data[] = new cacheable_object('two');
$data[] = new cacheable_object('three');
$cache->set($data);
</code>

__construct(array $items = array()   X-Ref
Constructs a new array object instance.

param: array $items

prepare_to_cache()   X-Ref
Returns the data to cache for this object.

return: array An array of cache_cached_object instances.

wake_from_cache($data)   X-Ref
Returns the cacheable_object_array that was originally sent to the cache.

param: array $data
return: cacheable_object_array