MediaWiki 1.42.1
ObjectCacheFactory Class Reference

Factory for cache objects as configured in the ObjectCaches setting. More...

Public Member Functions

 __construct (ServiceOptions $options, StatsFactory $stats, Spi $loggerSpi, callable $dbLoadBalancerFactory, string $domainId)
 
 clear ()
 Clear all the cached instances.
 
 getInstance ( $id)
 Get a cached instance of the specified type of cache object.
 
 getLocalServerInstance ( $fallback=CACHE_NONE)
 Factory function for CACHE_ACCEL (referenced from configuration)
 
 newFromParams (array $params)
 
 setInstanceForTesting ( $cacheId, BagOStuff $cache)
 

Detailed Description

Factory for cache objects as configured in the ObjectCaches setting.

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:

  • ObjectCacheFactory::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.
  • ObjectCacheFactory::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.

Since
1.42

Definition at line 59 of file ObjectCacheFactory.php.

Constructor & Destructor Documentation

◆ __construct()

ObjectCacheFactory::__construct ( ServiceOptions $options,
StatsFactory $stats,
Spi $loggerSpi,
callable $dbLoadBalancerFactory,
string $domainId )

Member Function Documentation

◆ clear()

ObjectCacheFactory::clear ( )

Clear all the cached instances.

Definition at line 307 of file ObjectCacheFactory.php.

◆ getInstance()

ObjectCacheFactory::getInstance ( $id)

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

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

Definition at line 151 of file ObjectCacheFactory.php.

◆ getLocalServerInstance()

ObjectCacheFactory::getLocalServerInstance ( $fallback = CACHE_NONE)

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

Definition at line 292 of file ObjectCacheFactory.php.

References $fallback, and CACHE_NONE.

◆ newFromParams()

ObjectCacheFactory::newFromParams ( array $params)
Access: internal
Using this method directly outside of MediaWiki core is discouraged. Use getInstance() instead and supply the ID of the cache instance to be looked up.

Create a new cache object from parameters specification supplied.

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

Definition at line 174 of file ObjectCacheFactory.php.

References $params.

◆ setInstanceForTesting()

ObjectCacheFactory::setInstanceForTesting ( $cacheId,
BagOStuff $cache )
Access: internal
For tests ONLY.
Parameters
string | int$cacheId
BagOStuff$cache
Returns
void

Definition at line 318 of file ObjectCacheFactory.php.


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