Search moodle.org's
Developer Documentation

See Release Notes

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

(no description)

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

Defines 1 class

allow_temporary_caches:: (3 methods):
  __construct()
  __destruct()
  is_allowed()


Class: allow_temporary_caches  - X-Ref

Create and keep an instance of this class to allow temporary caches when caches are disabled.

This class works together with code in {@see cache_factory_disabled}.

The intention is that temporary cache should be short-lived (not for the entire install process),
which avoids two problems: first, that we might run out of memory for the caches, and second,
that some code e.g. install.php/upgrade.php files, is entitled to assume that caching is not
used and make direct database changes.

__construct()   X-Ref
Constructs an instance of this class.

Temporary caches will be allowed until this instance goes out of scope. Store this token
in a local variable, so that the caches have a limited life; do not save it outside your
function.

If cache is not disabled then normal (non-temporary) caches will be used, and this class
does nothing.

If an object of this class already exists then creating (or destroying) another one will
have no effect.

__destruct()   X-Ref
Destroys an instance of this class.

You do not need to call this manually; PHP will call it automatically when your variable
goes out of scope. If you do need to remove your token at other times, use unset($token);

If there are no other instances of this object, then all temporary caches will be discarded.

is_allowed()   X-Ref
Checks if temp caches are currently allowed.

return: bool True if allowed