117 if ( $this->hasCached ===
null ) {
142 if ( $this->cacheExpiry < 86400 * 3650 ) {
143 $message = $context->
msg(
144 'cachedspecial-viewing-cached-ttl',
145 $context->
getLanguage()->formatDuration( $this->cacheExpiry )
148 $message = $context->
msg(
149 'cachedspecial-viewing-cached-ts'
153 if ( $includePurgeLink ) {
154 $refreshArgs = $context->
getRequest()->getQueryValues();
155 unset( $refreshArgs[
'title'] );
156 $refreshArgs[
'action'] =
'purge';
158 $message .=
' ' . MediaWikiServices::getInstance()->getLinkRenderer()->makeLink(
160 $context->
msg(
'cachedspecial-refresh-now' )->text(),
176 if ( $this->cacheEnabled && $this->hasCached ===
null ) {
182 if ( $this->onInitHandler !==
null ) {
183 call_user_func( $this->onInitHandler, $this->hasCached );
205 if ( $this->cacheEnabled && $this->hasCached ) {
208 if ( $key ===
null ) {
209 reset( $this->cachedChunks );
210 $itemKey = key( $this->cachedChunks );
212 if ( $itemKey ===
null ) {
213 wfWarn(
"Attempted to get an item while the queue is empty in " . __METHOD__ );
214 } elseif ( !is_int( $itemKey ) ) {
215 wfWarn(
"Attempted to get item with non-numeric key while " .
216 "the next item in the queue has a key ($itemKey) in " . __METHOD__ );
218 $value = array_shift( $this->cachedChunks );
220 } elseif ( array_key_exists( $key, $this->cachedChunks ) ) {
221 $value = $this->cachedChunks[$key];
222 unset( $this->cachedChunks[$key] );
224 wfWarn(
"There is no item with key '$key' in this->cachedChunks in " . __METHOD__ );
227 if ( !is_array(
$args ) ) {
231 $value = $computeFunction( ...
$args );
233 if ( $this->cacheEnabled ) {
234 if ( $key ===
null ) {
235 $this->cachedChunks[] = $value;
237 $this->cachedChunks[$key] = $value;
252 if ( $this->cacheEnabled && $this->hasCached ===
false && !empty( $this->cachedChunks ) ) {
283 if ( $this->cacheKey === [] ) {
284 throw new MWException(
'No cache key set, so cannot obtain or save the CacheHelper values.' );
287 return ObjectCache::getLocalClusterInstance()->makeKey(
288 ...array_values( $this->cacheKey )
311 $this->hasCached =
false;
322 $this->onInitHandler = $handlerFunction;
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfGetCache( $cacheType)
Get a specific cache object.
Helper class for caching various elements in a single cache entry.
bool $cacheEnabled
If the cache is enabled or not.
saveCache()
Saves the HTML to the cache in case it got recomputed.
setOnInitializedHandler( $handlerFunction)
Sets a function that gets called when initialization of the cache is done.
array $cacheKey
Elements to build a cache key with.
getCachedValue( $computeFunction, $args=[], $key=null)
Get a cached value if available or compute it if not and then cache it if possible.
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.
getCacheKeyString()
Returns the cache key to use to cache this page's HTML output.
bool null $hasCached
Indicates if the to be cached content was already cached.
callable null $onInitHandler
Function that gets called when initialization is done.
setCacheEnabled( $cacheEnabled)
Sets if the cache should be enabled or not.
setCacheKey(array $cacheKey)
Sets the cache key that should be used.
array $cachedChunks
List of HTML chunks to be cached (if !hasCached) or that where cached (of hasCached).
rebuildOnDemand()
Rebuild the content, even if it's already cached.
getCachedNotice(IContextSource $context, $includePurgeLink=true)
Returns a message that notifies the user he/she is looking at a cached version of the page,...
initCaching()
Initializes the caching if not already done so.
int $cacheExpiry
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.
Interface for objects which can provide a MediaWiki context on request.
msg( $key,... $params)
This is the method for getting translated interface messages.