MediaWiki REL1_32
DependencyWrapper Class Reference

This class stores an arbitrary value along with its dependencies. More...

Collaboration diagram for DependencyWrapper:

Public Member Functions

 __construct ( $value=false, $deps=[])
 
 getValue ()
 Get the user-defined value.
 
 initialiseDeps ()
 Initialise dependency values in preparation for storing.
 
 isExpired ()
 Returns true if any of the dependencies have expired.
 
 storeToCache ( $cache, $key, $expiry=0)
 Store the wrapper to a cache.
 

Static Public Member Functions

static getValueFromCache ( $cache, $key, $expiry=0, $callback=false, $callbackParams=[], $deps=[])
 Attempt to get a value from the cache.
 

Private Attributes

CacheDependency[] $deps
 
 $value
 

Detailed Description

This class stores an arbitrary value along with its dependencies.

Users should typically only use DependencyWrapper::getValueFromCache(), rather than instantiating one of these objects directly.

Definition at line 31 of file CacheDependency.php.

Constructor & Destructor Documentation

◆ __construct()

DependencyWrapper::__construct (   $value = false,
  $deps = [] 
)
Parameters
mixed$valueThe user-supplied value
CacheDependency | CacheDependency[]$depsA dependency or dependency array. All dependencies must be objects implementing CacheDependency.

Definition at line 41 of file CacheDependency.php.

References $deps, and $value.

Member Function Documentation

◆ getValue()

DependencyWrapper::getValue ( )

Get the user-defined value.

Returns
bool|mixed

Definition at line 80 of file CacheDependency.php.

References $value.

◆ getValueFromCache()

static DependencyWrapper::getValueFromCache (   $cache,
  $key,
  $expiry = 0,
  $callback = false,
  $callbackParams = [],
  $deps = [] 
)
static

Attempt to get a value from the cache.

If the value is expired or missing, it will be generated with the callback function (if present), and the newly calculated value will be stored to the cache in a wrapper.

Parameters
BagOStuff$cache
string$keyThe cache key
int$expiryThe expiry timestamp or interval in seconds
bool | callable$callbackThe callback for generating the value, or false
array$callbackParamsThe function parameters for the callback
array$depsThe dependencies to store on a cache miss. Note: these are not the dependencies used on a cache hit! Cache hits use the stored dependency array.
Returns
mixed The value, or null if it was not present in the cache and no callback was defined.

Definition at line 113 of file CacheDependency.php.

References $cache, $deps, $value, and isExpired().

◆ initialiseDeps()

DependencyWrapper::initialiseDeps ( )

Initialise dependency values in preparation for storing.

This must be called before serialization.

Definition at line 70 of file CacheDependency.php.

References as.

Referenced by storeToCache().

◆ isExpired()

DependencyWrapper::isExpired ( )

Returns true if any of the dependencies have expired.

Returns
bool

Definition at line 56 of file CacheDependency.php.

References as.

Referenced by getValueFromCache().

◆ storeToCache()

DependencyWrapper::storeToCache (   $cache,
  $key,
  $expiry = 0 
)

Store the wrapper to a cache.

Parameters
BagOStuff$cache
string$key
int$expiry

Definition at line 91 of file CacheDependency.php.

References $cache, and initialiseDeps().

Member Data Documentation

◆ $deps

CacheDependency [] DependencyWrapper::$deps
private

Definition at line 34 of file CacheDependency.php.

Referenced by __construct(), and getValueFromCache().

◆ $value

DependencyWrapper::$value
private

Definition at line 32 of file CacheDependency.php.

Referenced by __construct(), getValue(), and getValueFromCache().


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