Go to the documentation of this file.
117 if ( is_null( $this->hasCached ) ) {
142 if ( $this->cacheExpiry < 86400 * 3650 ) {
144 'cachedspecial-viewing-cached-ttl',
145 $context->getLanguage()->formatDuration( $this->cacheExpiry )
149 'cachedspecial-viewing-cached-ts'
153 if ( $includePurgeLink ) {
154 $refreshArgs =
$context->getRequest()->getQueryValues();
155 unset( $refreshArgs[
'title'] );
156 $refreshArgs[
'action'] =
'purge';
158 $subPage =
$context->getTitle()->getFullText();
159 $subPage = explode(
'/', $subPage, 2 );
160 $subPage = count( $subPage ) > 1 ? $subPage[1] :
false;
162 $message .=
' ' . MediaWikiServices::getInstance()->getLinkRenderer()->makeLink(
164 $context->msg(
'cachedspecial-refresh-now' )->text(),
180 if ( $this->cacheEnabled && is_null( $this->hasCached ) ) {
186 if ( $this->onInitHandler !==
null ) {
187 call_user_func( $this->onInitHandler, $this->hasCached );
209 if ( $this->cacheEnabled && $this->hasCached ) {
212 if ( is_null( $key ) ) {
213 reset( $this->cachedChunks );
214 $itemKey = key( $this->cachedChunks );
216 if ( !is_int( $itemKey ) ) {
217 wfWarn(
"Attempted to get item with non-numeric key while " .
218 "the next item in the queue has a key ($itemKey) in " . __METHOD__ );
219 } elseif ( is_null( $itemKey ) ) {
220 wfWarn(
"Attempted to get an item while the queue is empty in " . __METHOD__ );
222 $value = array_shift( $this->cachedChunks );
224 } elseif ( array_key_exists( $key, $this->cachedChunks ) ) {
225 $value = $this->cachedChunks[$key];
226 unset( $this->cachedChunks[$key] );
228 wfWarn(
"There is no item with key '$key' in this->cachedChunks in " . __METHOD__ );
231 if ( !is_array(
$args ) ) {
235 $value = $computeFunction( ...
$args );
237 if ( $this->cacheEnabled ) {
238 if ( is_null( $key ) ) {
239 $this->cachedChunks[] = $value;
241 $this->cachedChunks[$key] = $value;
256 if ( $this->cacheEnabled && $this->hasCached ===
false && !empty( $this->cachedChunks ) ) {
287 if ( $this->cacheKey === [] ) {
288 throw new MWException(
'No cache key set, so cannot obtain or save the CacheHelper values.' );
292 ...array_values( $this->cacheKey )
315 $this->hasCached =
false;
326 $this->onInitHandler = $handlerFunction;
startCache( $cacheExpiry=null, $cacheEnabled=null)
Initializes the caching.
static getLocalClusterInstance()
Get the main cluster-local cache object.
getCachedNotice(IContextSource $context, $includePurgeLink=true)
Returns a message that notifies the user he/she is looking at a cached version of the page,...
setExpiry( $cacheExpiry)
Sets the time to live for the cache, in seconds or a unix timestamp indicating the point of expiry....
Interface for all classes implementing CacheHelper functionality.
setCacheEnabled( $cacheEnabled)
Sets if the cache should be enabled or not.
array $cachedChunks
List of HTML chunks to be cached (if !hasCached) or that where cached (of hasCached).
int $cacheExpiry
The time to live for the cache, in seconds or a unix timestamp indicating the point of expiry.
bool null $hasCached
Indicates if the to be cached content was already cached.
initCaching()
Initializes the caching if not already done so.
wfGetCache( $cacheType)
Get a specific cache object.
setCacheKey(array $cacheKey)
Sets the cache key that should be used.
getCachedValue( $computeFunction, $args=[], $key=null)
Get a cached value if available or compute it if not and then cache it if possible.
callable null $onInitHandler
Function that gets called when initialization is done.
saveCache()
Saves the HTML to the cache in case it got recomputed.
rebuildOnDemand()
Rebuild the content, even if it's already cached.
Interface for objects which can provide a MediaWiki context on request.
Helper class for caching various elements in a single cache entry.
bool $cacheEnabled
If the cache is enabled or not.
array $cacheKey
Elements to build a cache key with.
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
setOnInitializedHandler( $handlerFunction)
Sets a function that gets called when initialization of the cache is done.
getCacheKeyString()
Returns the cache key to use to cache this page's HTML output.