MediaWiki  REL1_22
CachedAction Class Reference

Abstract action class with scaffolding for caching HTML and other values in a single blob. More...

Inheritance diagram for CachedAction:
Collaboration diagram for CachedAction:

List of all members.

Public Member Functions

 addCachedHTML ($computeFunction, $args=array(), $key=null)
 Add some HTML to be cached.
 getCachedValue ($computeFunction, $args=array(), $key=null)
 Get a cached value if available or compute it if not and then cache it if possible.
 onCacheInitialized ($hasCached)
 Gets called after the cache got initialized.
 saveCache ()
 Saves the HTML to the cache in case it got recomputed.
 setCacheEnabled ($cacheEnabled)
 Sets if the cache should be enabled or not.
 setExpiry ($cacheExpiry)
 Sets the time to live for the cache, in seconds or a unix timestamp indicating the point of expiry.
 startCache ($cacheExpiry=null, $cacheEnabled=null)
 Initializes the caching.

Protected Member Functions

 getCacheKey ()
 Returns the variables used to constructed the cache key in an array.

Protected Attributes

boolean $cacheEnabled = true
 If the cache is enabled or not.
CacheHelper $cacheHelper
 CacheHelper object to which we forward the non-SpecialPage specific caching work.

Detailed Description

Abstract action class with scaffolding for caching HTML and other values in a single blob.

Before using any of the caching functionality, call startCache. After the last call to either getCachedValue or addCachedHTML, call saveCache.

To get a cached value or compute it, use getCachedValue like this: $this->getCachedValue( $callback );

To add HTML that should be cached, use addCachedHTML like this: $this->addCachedHTML( $callback );

The callback function is only called when needed, so do all your expensive computations here. This function should returns the HTML to be cached. It should not add anything to the PageOutput object!

Definition at line 46 of file CachedAction.php.


Member Function Documentation

CachedAction::addCachedHTML ( computeFunction,
args = array(),
key = null 
)

Add some HTML to be cached.

This is done by providing a callback function that should return the HTML to be added. It will only be called if the item is not in the cache yet or when the cache has been invalidated.

Since:
1.20
Parameters:
{function}$computeFunction
array$args
string | null$key

Definition at line 133 of file CachedAction.php.

CachedAction::getCachedValue ( computeFunction,
args = array(),
key = null 
)

Get a cached value if available or compute it if not and then cache it if possible.

The provided $computeFunction is only called when the computation needs to happen and should return a result value. $args are arguments that will be passed to the compute function when called.

Since:
1.20
Parameters:
{function}$computeFunction
array | mixed$args
string | null$key
Returns:
mixed

Implements ICacheHelper.

Definition at line 117 of file CachedAction.php.

CachedAction::getCacheKey ( ) [protected]

Returns the variables used to constructed the cache key in an array.

Since:
1.20
Returns:
array

Definition at line 165 of file CachedAction.php.

Gets called after the cache got initialized.

Since:
1.20
Parameters:
boolean$hasCached

Definition at line 180 of file CachedAction.php.

Saves the HTML to the cache in case it got recomputed.

Should be called after the last time anything is added via addCachedHTML.

Since:
1.20

Implements ICacheHelper.

Definition at line 143 of file CachedAction.php.

CachedAction::setCacheEnabled ( cacheEnabled)

Sets if the cache should be enabled or not.

Since:
1.20
Parameters:
boolean$cacheEnabled

Implements ICacheHelper.

Definition at line 69 of file CachedAction.php.

CachedAction::setExpiry ( cacheExpiry)

Sets the time to live for the cache, in seconds or a unix timestamp indicating the point of expiry.

Since:
1.20
Parameters:
integer$cacheExpiry

Implements ICacheHelper.

Definition at line 154 of file CachedAction.php.

CachedAction::startCache ( cacheExpiry = null,
cacheEnabled = null 
)

Initializes the caching.

Should be called before the first time anything is added via addCachedHTML.

Since:
1.20
Parameters:
integer | null$cacheExpirySets the cache expiry, either ttl in seconds or unix timestamp.
boolean | null$cacheEnabledSets if the cache should be enabled or not.

Implements ICacheHelper.

Definition at line 82 of file CachedAction.php.


Member Data Documentation

boolean CachedAction::$cacheEnabled = true [protected]

If the cache is enabled or not.

Since:
1.20

Definition at line 61 of file CachedAction.php.

CacheHelper CachedAction::$cacheHelper [protected]

CacheHelper object to which we forward the non-SpecialPage specific caching work.

Initialized in startCache.

Since:
1.20

Definition at line 54 of file CachedAction.php.


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