Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250620) (7d9030acd6e)
navigation_cache Class Reference

The navigation_cache class is used for global and settings navigation data. More...

Public Member Functions

 __construct ($area, $timeout=null)
 Contructor for the cache.
 
 __get ($key)
 Magic Method to retrieve a cached item by simply calling using = cache->key.
 
 __set ($key, $information)
 Magic method that simply uses {.
 
 cached ($key)
 Check the existence of the identifier in the cache.
 
 clear ()
 Deletes the entire cache area, forcing a fresh cache to be created.
 
 compare ($key, $value, $serialise=true)
 Compare something to it's equivilant in the cache.
 
 set ($key, $information)
 Sets some information in the session cache for later retrieval.
 
 volatile ($setting=true)
 Marks the cache as volatile (likely to change)
 

Static Public Member Functions

static destroy_volatile_caches ()
 Destroys all caches marked as volatile.
 

Public Attributes

int const CACHETIME = 0
 cache time information
 
int const CACHEUSERID = 1
 cache user id
 
int const CACHEVALUE = 2
 cache value
 

Static Public Attributes

static null array $volatilecaches = null
 An array of cache areas to expire on shutdown.
 

Protected Member Functions

 ensure_navigation_cache_initialised ()
 Ensure the navigation cache is initialised.
 

Protected Attributes

string $area
 A unique string to segregate this particular cache.
 
cache_session $cache
 The session cache instance.
 
array $session = []
 The current cache area data.
 

Detailed Description

The navigation_cache class is used for global and settings navigation data.

It provides an easy access to the session cache with TTL of 1800 seconds.

Example use: if (!$cache->viewdiscussion()) { // Code to do stuff and produce cachable content $cache->viewdiscussion = has_capability('mod/forum:viewdiscussion', $coursecontext); } $content = $cache->viewdiscussion;

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

navigation_cache::__construct ( $area,
$timeout = null )

Contructor for the cache.

Requires a area string be passed in.

Parameters
string$areaThe unique string to segregate this particular cache.
int$timeoutDeprecated since Moodle 4.5. The number of seconds to time the information out after

Member Function Documentation

◆ __get()

navigation_cache::__get ( $key)

Magic Method to retrieve a cached item by simply calling using = cache->key.

Parameters
mixed$keyThe identifier for the cached information
Return values
mixed|voidThe cached information or void if not found

◆ __set()

navigation_cache::__set ( $key,
$information )

Magic method that simply uses {.

See also
navigation_cache\set()} to store an item in the cache
Parameters
string | int$keyThe key to store the information against
mixed$informationThe information to cache

◆ cached()

navigation_cache::cached ( $key)

Check the existence of the identifier in the cache.

Parameters
string | int$keyThe identifier to check
Return values
boolTrue if the item exists in the cache, false otherwise

◆ compare()

navigation_cache::compare ( $key,
$value,
$serialise = true )

Compare something to it's equivilant in the cache.

Parameters
string$keyThe key to check
mixed$valueThe value to compare
bool$serialiseWhether to serialise the value before comparison this should only be set to false if the value is already serialised
Return values
boolTrue if the value is the same as the cached one, false otherwise

◆ destroy_volatile_caches()

static navigation_cache::destroy_volatile_caches ( )
static

Destroys all caches marked as volatile.

This function is static and works with the static volatilecaches property of navigation cache. It manually resets the cached areas back to an empty array.

◆ ensure_navigation_cache_initialised()

navigation_cache::ensure_navigation_cache_initialised ( )
protected

Ensure the navigation cache is initialised.

This is called for each access and ensures that no data is put into the cache before it is required.

◆ set()

navigation_cache::set ( $key,
$information )

Sets some information in the session cache for later retrieval.

Parameters
string | int$key
mixed$information

◆ volatile()

navigation_cache::volatile ( $setting = true)

Marks the cache as volatile (likely to change)

Any caches marked as volatile will be destroyed on shutdown by {

See also
navigation_node::destroy_volatile_caches()}
Parameters
bool$settingTrue to mark the cache as volatile, false to remove the volatile flag

Member Data Documentation

◆ $area

string navigation_cache::$area
protected

A unique string to segregate this particular cache.

It can either be unique to start a fresh cache or shared to use an existing cache.


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