48 function startCache( $cacheExpiry =
null, $cacheEnabled =
null );
175 if ( is_null( $this->hasCached ) ) {
200 if ( $this->cacheExpiry < 86400 * 3650 ) {
202 'cachedspecial-viewing-cached-ttl',
203 $context->getLanguage()->formatDuration( $this->cacheExpiry )
207 'cachedspecial-viewing-cached-ts'
211 if ( $includePurgeLink ) {
212 $refreshArgs =
$context->getRequest()->getQueryValues();
213 unset( $refreshArgs[
'title'] );
214 $refreshArgs[
'action'] =
'purge';
216 $subPage =
$context->getTitle()->getFullText();
217 $subPage = explode(
'/', $subPage, 2 );
218 $subPage = count( $subPage ) > 1 ? $subPage[1] :
false;
222 $context->msg(
'cachedspecial-refresh-now' )->escaped(),
238 if ( $this->cacheEnabled && is_null( $this->hasCached ) ) {
244 if ( $this->onInitHandler !==
false ) {
245 call_user_func( $this->onInitHandler, $this->hasCached );
267 if ( $this->cacheEnabled && $this->hasCached ) {
270 if ( is_null( $key ) ) {
271 $itemKey = array_keys( array_slice( $this->cachedChunks, 0, 1 ) );
272 $itemKey = array_shift( $itemKey );
274 if ( !is_integer( $itemKey ) ) {
275 wfWarn(
"Attempted to get item with non-numeric key while " .
276 "the next item in the queue has a key ($itemKey) in " . __METHOD__ );
277 } elseif ( is_null( $itemKey ) ) {
278 wfWarn(
"Attempted to get an item while the queue is empty in " . __METHOD__ );
280 $value = array_shift( $this->cachedChunks );
283 if ( array_key_exists( $key, $this->cachedChunks ) ) {
284 $value = $this->cachedChunks[$key];
285 unset( $this->cachedChunks[$key] );
287 wfWarn(
"There is no item with key '$key' in this->cachedChunks in " . __METHOD__ );
291 if ( !is_array(
$args ) ) {
295 $value = call_user_func_array( $computeFunction,
$args );
297 if ( $this->cacheEnabled ) {
298 if ( is_null( $key ) ) {
299 $this->cachedChunks[] =
$value;
301 $this->cachedChunks[$key] =
$value;
316 if ( $this->cacheEnabled && $this->hasCached ===
false && !empty( $this->cachedChunks ) ) {
347 if ( $this->cacheKey === [] ) {
348 throw new MWException(
'No cache key set, so cannot obtain or save the CacheHelper values.' );
351 return call_user_func_array(
'wfMemcKey', $this->cacheKey );
373 $this->hasCached =
false;
384 $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....
callable $onInitHandler
Function that gets called when initialization is done.
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.
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.
static link( $target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
the array() calling protocol came about after MediaWiki 1.4rc1.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Interface for all classes implementing CacheHelper functionality.
setExpiry( $cacheExpiry)
Sets the time to live for the cache, in seconds or a unix timestamp indicating the point of expiry....
setCacheEnabled( $cacheEnabled)
Sets if the cache should be enabled or not.
getCachedValue( $computeFunction, $args=[], $key=null)
Get a cached value if available or compute it if not and then cache it if possible.
saveCache()
Saves the HTML to the cache in case it got recomputed.
startCache( $cacheExpiry=null, $cacheEnabled=null)
Initializes the caching.
Interface for objects which can provide a MediaWiki context on request.