MediaWiki REL1_39
ObjectCache Class Reference

Functions to get cache objects. More...

Collaboration diagram for ObjectCache:

Static Public Member Functions

static clear ()
 Clear all the cached instances.
 
static getInstance ( $id)
 Get a cached instance of the specified type of cache object.
 
static getLocalClusterInstance ()
 Get the main cluster-local cache object.
 
static getLocalServerInstance ( $fallback=CACHE_NONE)
 Factory function for CACHE_ACCEL (referenced from configuration)
 
static makeLocalServerCache ()
 Create a new BagOStuff instance for local-server caching.
 
static newAnything ( $params)
 Factory function for CACHE_ANYTHING (referenced by configuration)
 
static newFromParams (array $params, Config $conf=null)
 Create a new cache object from parameters.
 

Static Public Attributes

static BagOStuff[] $instances = []
 Map of (id => BagOStuff)
 

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).

Primary entry points:

  • 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::getInstance( $cacheType ) Purpose: Special cases (like tiered memory/disk caches). Get a specific cache type by key in $wgObjectCaches.

All the above BagOStuff cache instances 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 65 of file ObjectCache.php.

Member Function Documentation

◆ clear()

static ObjectCache::clear ( )
static

Clear all the cached instances.

Definition at line 295 of file ObjectCache.php.

◆ getInstance()

static ObjectCache::getInstance ( $id)
static

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

Parameters
string | int$idA key in $wgObjectCaches.
Returns
BagOStuff

Definition at line 75 of file ObjectCache.php.

◆ getLocalClusterInstance()

static ObjectCache::getLocalClusterInstance ( )
static

Get the main cluster-local cache object.

Since
1.27
Returns
BagOStuff

Definition at line 286 of file ObjectCache.php.

References $wgMainCacheType.

Referenced by MediaWiki\ResourceLoader\ResourceLoader\saveModuleDependenciesInternal().

◆ getLocalServerInstance()

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

Factory function for CACHE_ACCEL (referenced from configuration)

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( [ 'fallback' => $fallbackType ] );
Parameters
int | string | array$fallbackFallback cache or parameter map with 'fallback'
Returns
BagOStuff
Exceptions
InvalidArgumentException
Since
1.27

Definition at line 268 of file ObjectCache.php.

References $cache, $fallback, and CACHE_NONE.

◆ makeLocalServerCache()

static ObjectCache::makeLocalServerCache ( )
static

Create a new BagOStuff instance for local-server caching.

Only use this if you explicitly require the creation of a fresh instance. Whenever possible, use or inject the object from MediaWikiServices::getLocalServerObjectCache() instead.

NOTE: This method is called very early via Setup.php by ExtensionRegistry, and thus must remain fairly standalone so as to not cause initialization of the MediaWikiServices singleton.

Since
1.35
Returns
BagOStuff

Definition at line 313 of file ObjectCache.php.

◆ newAnything()

static ObjectCache::newAnything ( $params)
static

Factory function for CACHE_ANYTHING (referenced by configuration)

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 226 of file ObjectCache.php.

References $cache, $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, CACHE_ANYTHING, CACHE_DB, and CACHE_NONE.

◆ newFromParams()

static ObjectCache::newFromParams ( array $params,
Config $conf = null )
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.
Config | null$conf(Since 1.35)
Returns
BagOStuff
Exceptions
InvalidArgumentException

Definition at line 140 of file ObjectCache.php.

References $args.

Member Data Documentation

◆ $instances

BagOStuff [] ObjectCache::$instances = []
static

Map of (id => BagOStuff)

Definition at line 67 of file ObjectCache.php.


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