BlueSpice MediaWiki master
 All Classes Namespaces Files Functions Variables Groups Pages
MessageCache Class Reference
Collaboration diagram for MessageCache:

Public Member Functions

 __construct (WANObjectCache $wanCache, BagOStuff $clusterCache, BagOStuff $serverCache, $useDB, $expiry)
 
 getParserOptions ()
 
 replace ($title, $text)
 
 get ($key, $useDB=true, $langcode=true, $isFullKey=false)
 
 getMsgFromNamespace ($title, $code)
 
 transform ($message, $interface=false, $language=null, $title=null)
 
 getParser ()
 
 parse ($text, $title=null, $linestart=true, $interface=false, $language=null)
 
 disable ()
 
 enable ()
 
 isDisabled ()
 
 clear ()
 
 figureMessage ($key)
 
 getAllMessageKeys ($code)
 
 updateMessageOverride (Title $title, Content $content=null)
 
 getCheckKey ($code)
 

Static Public Member Functions

static singleton ()
 
static destroyInstance ()
 
static normalizeKey ($key)
 

Public Attributes

const FOR_UPDATE = 1
 
const WAIT_SEC = 15
 
const LOCK_TTL = 30
 

Protected Member Functions

 getLocalCache ($code)
 
 saveToLocalCache ($code, $cache)
 
 load ($code, $mode=null)
 
 loadFromDBWithLock ($code, array &$where, $mode=null)
 
 loadFromDB ($code, $mode=null)
 
 isCacheExpired ($cache)
 
 saveToCaches (array $cache, $dest, $code=false)
 
 getValidationHash ($code)
 
 setValidationHash ($code, array $cache)
 
 getReentrantScopedLock ($key, $timeout=self::WAIT_SEC)
 
 getMessageFromFallbackChain ($lang, $lckey, $useDB)
 

Protected Attributes

 $mCache
 
 $mCacheVolatile = []
 
 $mDisable
 
 $mExpiry
 
 $mParserOptions
 
 $mParser
 
 $mLoadedLanguages = []
 
 $mInParser = false
 
 $wanCache
 
 $clusterCache
 
 $srvCache
 

Detailed Description

Message cache Performs various MediaWiki namespace-related functions

Constructor & Destructor Documentation

MessageCache::__construct ( WANObjectCache  $wanCache,
BagOStuff  $clusterCache,
BagOStuff  $serverCache,
  $useDB,
  $expiry 
)
Parameters
WANObjectCache$wanCache
BagOStuff$clusterCache
BagOStuff$serverCache
bool$useDBWhether to look for message overrides (e.g. MediaWiki: pages)
int$expiryLifetime for cache.
See Also
$mExpiry.

Member Function Documentation

MessageCache::clear ( )

Clear all stored messages in global and local cache

Mainly used after a mass rebuild

static MessageCache::destroyInstance ( )
static

Destroy the singleton instance

Since
1.18
MessageCache::figureMessage (   $key)
Parameters
string$key
Returns
array
MessageCache::get (   $key,
  $useDB = true,
  $langcode = true,
  $isFullKey = false 
)

Get a message from either the content language or the user language.

First, assemble a list of languages to attempt getting the message from. This chain begins with the requested language and its fallbacks and then continues with the content language and its fallbacks. For each language in the chain, the following process will occur (in this order):

  1. If a language-specific override, i.e., [[MW:msg/lang]], is available, use that. Note: for the content language, there is no /lang subpage.
  2. Fetch from the static CDB cache.
  3. If available, check the database for fallback language overrides.

This process provides a number of guarantees. When changing this code, make sure all of these guarantees are preserved.

  • If the requested language is not the content language, then the CDB cache for that specific language will take precedence over the root database page ([[MW:msg]]).
  • Fallbacks will be just that: fallbacks. A fallback language will never be reached if the message is available anywhere in the language for which it is a fallback.
Parameters
string$keyThe message key
bool$useDBIf true, look for the message in the DB, false to use only the compiled l10n cache.
bool | string | object$langcodeCode of the language to get the message for.
  • If string and a valid code, will create a standard language object
  • If string but not a valid code, will create a basic language object
  • If boolean and false, create object from the current users language
  • If boolean and true, create object from the wikis content language
  • If language object, use it as given
bool$isFullKeySpecifies whether $key is a two part key "msg/lang".
Exceptions
MWExceptionWhen given an invalid key
Returns
string|bool False if the message doesn't exist, otherwise the message (which can be empty)
MessageCache::getAllMessageKeys (   $code)

Get all message keys stored in the message cache for a given language. If $code is the content language code, this will return all message keys for which MediaWiki:msgkey exists. If $code is another language code, this will ONLY return message keys for which MediaWiki:msgkey/$code exists.

Parameters
string$codeLanguage code
Returns
array Array of message keys (strings)
MessageCache::getCheckKey (   $code)
Parameters
string$codeLanguage code
Returns
string WAN cache key usable as a "check key" against language page edits
MessageCache::getLocalCache (   $code)
protected

Try to load the cache from APC.

Parameters
string$codeOptional language code, see documenation of load().
Returns
array|bool The cache array, or false if not in cache.
MessageCache::getMessageFromFallbackChain (   $lang,
  $lckey,
  $useDB 
)
protected

Given a language, try and fetch messages from that language.

Will also consider fallbacks of that language, the site language, and fallbacks for the site language.

See Also
MessageCache::get
Parameters
Language | StubObject$langPreferred language
string$lckeyLowercase key for the message (as for localisation cache)
bool$useDBWhether to include messages from the wiki database
Returns
string|bool The message, or false if not found
MessageCache::getMsgFromNamespace (   $title,
  $code 
)

Get a message from the MediaWiki namespace, with caching. The key must first be converted to two-part lang/msg form if necessary.

Unlike self::get(), this function doesn't resolve fallback chains, and some callers require this behavior. LanguageConverter::parseCachedTable() and self::get() are some examples in core.

Parameters
string$titleMessage cache key with initial uppercase letter
string$codeCode denoting the language to try
Returns
string|bool The message, or false if it does not exist or on error
MessageCache::getParser ( )
Returns
Parser
MessageCache::getParserOptions ( )

ParserOptions is lazy initialised.

Returns
ParserOptions
MessageCache::getReentrantScopedLock (   $key,
  $timeout = self::WAIT_SEC 
)
protected
Parameters
string$keyA language message cache key that stores blobs
int$timeoutWait timeout in seconds
Returns
null|ScopedCallback
MessageCache::getValidationHash (   $code)
protected

Get the md5 used to validate the local APC cache

Parameters
string$code
Returns
array (hash or false, bool expiry/volatility status)
MessageCache::isCacheExpired (   $cache)
protected

Is the given cache array expired due to time passing or a version change?

Parameters
array$cache
Returns
bool
MessageCache::isDisabled ( )

Whether DB/cache usage is disabled for determining messages

If so, this typically indicates either:

  • a) load() failed to find a cached copy nor query the DB
  • b) we are in a special context or error mode that cannot use the DB If the DB is ignored, any derived HTML output or cached objects may be wrong. To avoid long-term cache pollution, TTLs can be adjusted accordingly.
Returns
bool
Since
1.27
MessageCache::load (   $code,
  $mode = null 
)
protected

Loads messages from caches or from database in this order: (1) local message cache (if $wgUseLocalMessageCache is enabled) (2) memcached (3) from the database.

When succesfully loading from (2) or (3), all higher level caches are updated for the newest version.

Nothing is loaded if member variable mDisable is true, either manually set by calling code or if message loading fails (is this possible?).

Returns true if cache is already populated or it was succesfully populated, or false if populating empty cache fails. Also returns true if MessageCache is disabled.

Parameters
string$codeLanguage to which load messages
int$modeUse MessageCache::FOR_UPDATE to skip process cache [optional]
Exceptions
MWException
Returns
bool
MessageCache::loadFromDB (   $code,
  $mode = null 
)
protected

Loads cacheable messages from the database. Messages bigger than $wgMaxMsgCacheEntrySize are assigned a special value, and are loaded on-demand from the database later.

Parameters
string$codeLanguage code
int$modeUse MessageCache::FOR_UPDATE to skip process cache
Returns
array Loaded messages for storing in caches
MessageCache::loadFromDBWithLock (   $code,
array &  $where,
  $mode = null 
)
protected
Parameters
string$code
array&$whereList of wfDebug() comments
int$modeUse MessageCache::FOR_UPDATE to use DB_MASTER
Returns
bool|string True on success or one of ("cantacquire", "disabled")

Cache save has failed.

There are two main scenarios where this could be a problem:

  • The cache is more than the maximum size (typically 1MB compressed).
  • Memcached has no space remaining in the relevant slab class. This is unlikely with recent versions of memcached.

Either way, if there is a local cache, nothing bad will happen. If there is no local cache, disabling the message cache for all requests avoids incurring a loadFromDB() overhead on every request, and thus saves the wiki from complete downtime under moderate traffic conditions.

static MessageCache::normalizeKey (   $key)
static

Normalize message key input

Parameters
string$keyInput message key to be normalized
Returns
string Normalized message key
MessageCache::parse (   $text,
  $title = null,
  $linestart = true,
  $interface = false,
  $language = null 
)
Parameters
string$text
Title$title
bool$linestartWhether or not this is at the start of a line
bool$interfaceWhether this is an interface message
Language | string$languageLanguage code
Returns
ParserOutput|string
MessageCache::replace (   $title,
  $text 
)

Updates cache as necessary when message page is changed

Parameters
string$titleMessage cache key with initial uppercase letter
string | bool$textNew contents of the page (false if deleted)
MessageCache::saveToCaches ( array  $cache,
  $dest,
  $code = false 
)
protected

Shortcut to update caches.

Parameters
array$cacheCached messages with a version.
string$destEither "local-only" to save to local caches only or "all" to save to all caches.
string | bool$codeLanguage code (default: false)
Returns
bool
MessageCache::saveToLocalCache (   $code,
  $cache 
)
protected

Save the cache to APC.

Parameters
string$code
array$cacheThe cache array
MessageCache::setValidationHash (   $code,
array  $cache 
)
protected

Set the md5 used to validate the local disk cache

If $cache has a 'LATEST' UNIX timestamp key, then the hash will not be treated as "volatile" by getValidationHash() for the next few seconds. This is triggered when $cache is generated using FOR_UPDATE mode.

Parameters
string$code
array$cacheCached messages with a version
static MessageCache::singleton ( )
static

Get the signleton instance of this class

Since
1.18
Returns
MessageCache
MessageCache::transform (   $message,
  $interface = false,
  $language = null,
  $title = null 
)
Parameters
string$message
bool$interface
Language$language
Title$title
Returns
string
MessageCache::updateMessageOverride ( Title  $title,
Content  $content = null 
)

Purge message caches when a MediaWiki: page is created, updated, or deleted

Parameters
Title$titleMessage page title
Content | null$contentNew content for edit/create, null on deletion
Since
1.29

Member Data Documentation

array MessageCache::$mCache
protected

Process local cache of loaded messages that are defined in MediaWiki namespace. First array level is a language code, second level is message key and the values are either message content prefixed with space, or !NONEXISTENT for negative caching.

bool MessageCache::$mDisable
protected

Should mean that database cannot be used, but check

MessageCache::$mExpiry
protected

Lifetime for cache, used by object caching. Set on construction, see __construct().

array MessageCache::$mLoadedLanguages = []
protected

Variable for tracking which variables are already loaded

const MessageCache::LOCK_TTL = 30

How long memcached locks last

const MessageCache::WAIT_SEC = 15

How long to wait for memcached locks


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