MediaWiki  1.27.4
ObjectCache Class Reference

Functions to get cache objects. More...

Collaboration diagram for ObjectCache:

Static Public Member Functions

static clear ()
 Clear all the cached instances. More...
 
static getDefaultKeyspace ()
 Get the default keyspace for this wiki. More...
 
static getInstance ($id)
 Get a cached instance of the specified type of cache object. More...
 
static getLocalClusterInstance ()
 Get the main cluster-local cache object. More...
 
static getLocalServerInstance ($fallback=CACHE_NONE)
 Factory function for CACHE_ACCEL (referenced from DefaultSettings.php) More...
 
static getMainStashInstance ()
 Get the cache object for the main stash. More...
 
static getMainWANInstance ()
 Get the main WAN cache object. More...
 
static getWANInstance ($id)
 Get a cached instance of the specified type of WAN cache object. More...
 
static newAccelerator ($params=[], $fallback=null)
 
static newAnything ($params)
 Factory function for CACHE_ANYTHING (referenced from DefaultSettings.php) More...
 
static newFromId ($id)
 Create a new cache object of the specified type. More...
 
static newFromParams ($params)
 Create a new cache object from parameters. More...
 
static newWANCacheFromId ($id)
 Create a new cache object of the specified type. More...
 

Static Public Attributes

static BagOStuff[] $instances = []
 Map of (id => BagOStuff) More...
 
static WANObjectCache[] $wanInstances = []
 Map of (id => WANObjectCache) More...
 

Detailed Description

Functions to get cache objects.

The word "cache" has two main dictionary meanings, and both are used in this factory class. They are:

  • a) Cache (the computer science definition). A place to store copies or computations on existing data for higher access speeds.
  • b) Storage. A place to store lightweight data that is not canonically stored anywhere else (e.g. a "hoard" of objects).

The former should always use strongly consistent stores, so callers don't have to deal with stale reads. The later may be eventually consistent, but callers can use BagOStuff:READ_LATEST to see the latest available data.

Primary entry points:

  • ObjectCache::getMainWANInstance() Purpose: Memory cache. Stored in the local data-center's main cache (keyspace different from local-cluster cache). Delete events are broadcasted to other DCs main cache. See WANObjectCache for details.
  • ObjectCache::getLocalServerInstance( $fallbackType ) Purpose: Memory cache for very hot keys. Stored only on the individual web server (typically APC or APCu for web requests, and EmptyBagOStuff in CLI mode). Not replicated to the other servers.
  • ObjectCache::getLocalClusterInstance() Purpose: Memory storage for per-cluster coordination and tracking. A typical use case would be a rate limit counter or cache regeneration mutex. Stored centrally within the local data-center. Not replicated to other DCs. Configured by $wgMainCacheType.
  • ObjectCache::getMainStashInstance() Purpose: Ephemeral global storage. Stored centrally within the primary data-center. Changes are applied there first and replicated to other DCs (best-effort). To retrieve the latest value (e.g. not from a slave), use BagOStuff::READ_LATEST. This store may be subject to LRU style evictions.
  • ObjectCache::getInstance( $cacheType ) Purpose: Special cases (like tiered memory/disk caches). Get a specific cache type by key in $wgObjectCaches.

All the above cache instances (BagOStuff and WANObjectCache) have their makeKey() method scoped to the current wiki ID. Use makeGlobalKey() to avoid this scoping when using keys that need to be shared amongst wikis.

Definition at line 80 of file ObjectCache.php.

Member Function Documentation

static ObjectCache::clear ( )
static

Clear all the cached instances.

Definition at line 377 of file ObjectCache.php.

Referenced by Installer\__construct(), and ForkController\prepareEnvironment().

static ObjectCache::getDefaultKeyspace ( )
static

Get the default keyspace for this wiki.

This is either the value of the CachePrefix configuration variable, or (if the former is unset) the DBname configuration variable, with DBprefix (if defined).

Returns
string

Definition at line 142 of file ObjectCache.php.

References global, and wfWikiID().

static ObjectCache::getInstance (   $id)
static

Get a cached instance of the specified type of cache object.

Parameters
string$idA key in $wgObjectCaches.
Returns
BagOStuff

Definition at line 92 of file ObjectCache.php.

Referenced by MediaWiki\Session\SessionManager\__construct(), Preprocessor\cacheGetTree(), Preprocessor\cacheSetTree(), and LanguageConverter\loadTables().

static ObjectCache::getLocalServerInstance (   $fallback = CACHE_NONE)
static

Factory function for CACHE_ACCEL (referenced from DefaultSettings.php)

This will look for any APC or APCu style server-local cache. A fallback cache can be specified if none is found.

// Direct calls
ObjectCache::getLocalServerInstance( $fallbackType );

// From $wgObjectCaches via newFromParams()
ObjectCache::getLocalServerInstance( array( 'fallback' => $fallbackType ) );
Parameters
int | string | array$fallbackFallback cache or parameter map with 'fallback'
Returns
BagOStuff
Exceptions
MWException
Since
1.27

Definition at line 255 of file ObjectCache.php.

References $fallback, CACHE_NONE, and wfIniGetBool().

Referenced by FileContentsHasher\__construct(), LoadMonitorMySQL\__construct(), DBLockManager\__construct(), ExtensionRegistry\__construct(), LoadBalancer\__construct(), SwiftFileBackend\__construct(), MessageCache\__construct(), DatabaseBase\__construct(), ResourceLoaderFileModule\compileLessFile(), ResourceLoader\filter(), IcuCollation\getFirstLetterData(), DateFormatter\getInstance(), TransformationalImageHandler\getMagickVersion(), UIDGenerator\getSequentialPerNodeIDs(), TemplateParser\getTemplate(), and MWCryptHKDF\singleton().

static ObjectCache::getMainStashInstance ( )
static

Get the cache object for the main stash.

Stash objects are BagOStuff instances suitable for storing light weight data that is not canonically stored elsewhere (such as RDBMS). Stashes should be configured to propagate changes to all data-centers.

Callers should be prepared for:

  • a) Writes to be slower in non-"primary" (e.g. HTTP GET/HEAD only) DCs
  • b) Reads to be eventually consistent, e.g. for get()/getMulti() In general, this means avoiding updates on idempotent HTTP requests and avoiding an assumption of perfect serializability (or accepting anomalies). Reads may be eventually consistent or data might rollback as nodes flap. Callers can use BagOStuff:READ_LATEST to see the latest available data.
Returns
BagOStuff
Since
1.26

Definition at line 368 of file ObjectCache.php.

References $wgMainStash, and global.

Referenced by SiteStatsUpdate\adjustPending(), WikiPage\doDeleteArticleReal(), SiteStatsUpdate\getPendingDeltas(), UploadBase\getSessionStatus(), LBFactory\newChronologyProtector(), SiteStatsUpdate\removePendingDeltas(), UploadBase\setSessionStatus(), and Article\showMissingArticle().

static ObjectCache::getMainWANInstance ( )
static

Get the main WAN cache object.

Since
1.26
Returns
WANObjectCache

Definition at line 344 of file ObjectCache.php.

References $wgMainWANCache, and global.

Referenced by JobQueueDB\__construct(), MessageBlobStore\__construct(), MessageCache\__construct(), Skin\buildSidebar(), FeedUtils\checkPurge(), LocalRepo\checkRedirect(), User\clearSharedCache(), FormatMetadata\fetchExtendedMetadata(), FileBackendGroup\get(), JobQueueGroup\getCachedConfigVar(), ForeignDBFile\getDescriptionText(), File\getDescriptionText(), DifferenceEngine\getDiffBody(), DjVuHandler\getDimensionInfo(), ApiHelp\getHelp(), BacklinkCache\getNumLinks(), ForeignAPIRepo\getThumbUrlFromCache(), User\getTouched(), ForeignAPIRepo\httpGetCached(), InfoAction\invalidateCache(), Interwiki\invalidateCache(), LocalFile\invalidateCache(), LocalRepo\invalidateImageRedirect(), Block\isWhitelistedFromAutoblocks(), ChangeTags\listExplicitlyDefinedTags(), ChangeTags\listExtensionActivatedTags(), ChangeTags\listExtensionDefinedTags(), Interwiki\load(), ChangesFeed\loadFromCache(), LocalFile\loadFromCache(), User\loadFromCache(), AjaxResponse\loadFromMemcached(), Revision\loadText(), ApiMain\makeHelpMsg(), SiteStats\numberingroup(), InfoAction\pageCounts(), BacklinkCache\partition(), User\purge(), ForeignAPIFile\purgeDescriptionPage(), Article\purgePatrolFooterCache(), ChangeTags\purgeTagCacheAll(), ChangeTags\purgeTagUsageCache(), ForeignAPIFile\purgeThumbnails(), ParserTest\runTest(), ChangesFeed\saveToCache(), LocalFile\saveToCache(), User\saveToCache(), MediaWikiTestCase\setUp(), Article\showPatrolFooter(), AjaxResponse\storeInMemcached(), ChangeTags\tagUsageStatistics(), User\touch(), and ResourceLoaderModule\validateScriptFile().

static ObjectCache::getWANInstance (   $id)
static

Get a cached instance of the specified type of WAN cache object.

Since
1.26
Parameters
string$idA key in $wgWANObjectCaches.
Returns
WANObjectCache

Definition at line 107 of file ObjectCache.php.

Referenced by WANObjectCacheTest\setUp().

static ObjectCache::newAccelerator (   $params = [],
  $fallback = null 
)
static
Parameters
array$params[optional] Array key 'fallback' for $fallback.
int | string$fallbackFallback cache, e.g. (CACHE_NONE, "hash") (since 1.24)
Returns
BagOStuff
Deprecated:
1.27

Definition at line 281 of file ObjectCache.php.

References $fallback, and $params.

Referenced by LanguageConverter\convertNamespace().

static ObjectCache::newAnything (   $params)
static

Factory function for CACHE_ANYTHING (referenced from DefaultSettings.php)

CACHE_ANYTHING means that stuff has to be cached, not caching is not an option. If a caching method is configured for any of the main caches ($wgMainCacheType, $wgMessageCacheType, $wgParserCacheType), then CACHE_ANYTHING will effectively be an alias to the configured cache choice for that. If no cache choice is configured (by default $wgMainCacheType is CACHE_NONE), then CACHE_ANYTHING will forward to CACHE_DB.

Parameters
array$params
Returns
BagOStuff

Definition at line 221 of file ObjectCache.php.

References $cache, $wgMessageCacheType, $wgParserCacheType, as, CACHE_ANYTHING, CACHE_DB, CACHE_NONE, and global.

static ObjectCache::newFromId (   $id)
static

Create a new cache object of the specified type.

Parameters
string$idA key in $wgObjectCaches.
Returns
BagOStuff
Exceptions
MWException

Definition at line 122 of file ObjectCache.php.

References $wgObjectCaches, and global.

Referenced by BagOStuffTest\setUp(), and BagOStuffTest\testMakeKey().

static ObjectCache::newFromParams (   $params)
static

Create a new cache object from parameters.

Parameters
array$paramsMust have 'factory' or 'class' property.
  • factory: Callback passed $params that returns BagOStuff.
  • class: BagOStuff subclass constructed with $params.
  • loggroup: Alias to set 'logger' key with LoggerFactory group.
  • .. Other parameters passed to factory or class.
Returns
BagOStuff
Exceptions
MWException

Definition at line 164 of file ObjectCache.php.

References $GLOBALS, and $params.

Referenced by MemcLockManager\__construct().

static ObjectCache::newWANCacheFromId (   $id)
static

Create a new cache object of the specified type.

Since
1.26
Parameters
string$idA key in $wgWANObjectCaches.
Returns
WANObjectCache
Exceptions
MWException

Definition at line 301 of file ObjectCache.php.

References $params, $wgWANObjectCaches, as, and global.

Member Data Documentation

WANObjectCache [] ObjectCache::$wanInstances = []
static

Map of (id => WANObjectCache)

Definition at line 84 of file ObjectCache.php.


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