Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
navigation_cache Class Reference

The cache class used by global navigation and settings navigation. More...

Public Member Functions

 __construct ($area, $timeout=1800)
 Contructor for the cache.
 
 __get ($key)
 Magic Method to retrieve something by simply calling using = cache->key.
 
 __set ($key, $information)
 Magic method that simply uses set(); to store something in the cache.
 
 cached ($key)
 Check the existence of the identifier in the cache.
 
 clear ()
 Wipes the entire cache, good to force regeneration.
 
 compare ($key, $value, $serialise=true)
 Compare something to it's equivilant in the cache.
 
 set ($key, $information)
 Sets some information against the cache (session) for later retrieval.
 
 volatile ($setting=true)
 Marks the cache as being 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
 An array of navigation cache areas to expire on shutdown.
 

Protected Member Functions

 ensure_session_cache_initialised ()
 Used to set up the cache within the SESSION.
 
 garbage_collection ()
 Checks all cache entries and removes any that have expired, good ole cleanup.
 

Protected Attributes

string $area
 The string to use to segregate this particular cache.
 
int $creation
 represents the time created
 
stdClass $currentcontext
 The current context.
 
array $session
 An array of session keys.
 
int $timeout
 a time that the information will time out
 

Detailed Description

The cache class used by global navigation and settings navigation.

It is basically an easy access point to session with a bit of smarts to make sure that the information that is cached is valid still.

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 = 1800 )

Contructor for the cache.

Requires two arguments

Parameters
string$areaThe string to use to segregate this particular cache it can either be unique to start a fresh cache or if you want to share a cache then make it the string used in the original cache
int$timeoutThe number of seconds to time the information out after

Member Function Documentation

◆ __get()

navigation_cache::__get ( $key)

Magic Method to retrieve something by simply calling using = cache->key.

Parameters
mixed$keyThe identifier for the information you want out again
Return values
void|mixedEither void or what ever was put in

◆ __set()

navigation_cache::__set ( $key,
$information )

Magic method that simply uses set(); to store something in the cache.

Parameters
string | int$key
mixed$information

◆ cached()

navigation_cache::cached ( $key)

Check the existence of the identifier in the cache.

Parameters
string | int$key
Return values
bool

◆ compare()

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

Compare something to it's equivilant in the cache.

Parameters
string$key
mixed$value
bool$serialiseWhether to serialise the value before comparison this should only be set to false if the value is already serialised
Return values
boolIf the value is the same false if it is not set or doesn't match

◆ destroy_volatile_caches()

static navigation_cache::destroy_volatile_caches ( )
static

Destroys all caches marked as volatile.

This function is static and works in conjunction with the static volatilecaches property of navigation cache. Because this function is static it manually resets the cached areas back to an empty array.

◆ ensure_session_cache_initialised()

navigation_cache::ensure_session_cache_initialised ( )
protected

Used to set up the cache within the SESSION.

This is called for each access and ensure that we don't put anything into the session before it is required.

◆ set()

navigation_cache::set ( $key,
$information )

Sets some information against the cache (session) for later retrieval.

Parameters
string | int$key
mixed$information

◆ volatile()

navigation_cache::volatile ( $setting = true)

Marks the cache as being volatile (likely to change)

Any caches marked as volatile will be destroyed at the on shutdown by navigation_node::destroy_volatile_caches() which is registered as a shutdown function if any caches are marked as volatile.

Parameters
bool$settingTrue to destroy the cache false not too

Member Data Documentation

◆ $area

string navigation_cache::$area
protected

The string to use to segregate this particular cache.

It can either be unique to start a fresh cache or if you want to share a cache then make it the string used in the original cache.


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