MediaWiki master
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.
 
 getAnythingId ()
 Get the ID that will be used for CACHE_ANYTHING.
 
 getInstance ( $id)
 Get a cached instance of the specified type of cache object.
 
 getLocalClusterInstance ()
 Get the main cluster-local cache object.
 
 getLocalServerInstance ( $fallback=CACHE_NONE)
 Factory function for CACHE_ACCEL (referenced from configuration)
 
 isDatabaseId ( $id)
 Determine whether a config ID would access the database.
 
 newFromParams (array $params)
 Create a new cache object from parameters specification supplied.
 

Static Public Member Functions

static makeLocalServerCache (string $keyspace)
 Create a new BagOStuff instance for local-server caching.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 

Static Public Attributes

static string $localServerCacheClass
 

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

  • 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 74 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 331 of file ObjectCacheFactory.php.

◆ getAnythingId()

ObjectCacheFactory::getAnythingId ( )

Get the ID that will be used for CACHE_ANYTHING.

Access: internal
Returns
string|int

Definition at line 360 of file ObjectCacheFactory.php.

References CACHE_ACCEL, CACHE_ANYTHING, CACHE_DB, and CACHE_NONE.

◆ 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 175 of file ObjectCacheFactory.php.

◆ getLocalClusterInstance()

ObjectCacheFactory::getLocalClusterInstance ( )

Get the main cluster-local cache object.

Since
1.43, previously on ObjectCache.php since 1.27
Returns
BagOStuff

Definition at line 457 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 316 of file ObjectCacheFactory.php.

References $fallback, and CACHE_NONE.

◆ isDatabaseId()

ObjectCacheFactory::isDatabaseId ( $id)

Determine whether a config ID would access the database.

Access: internal
For use by ServiceWiring.php
Parameters
string | int$idA key in $wgObjectCaches
Returns
bool

Definition at line 430 of file ObjectCacheFactory.php.

References CACHE_ANYTHING.

◆ makeLocalServerCache()

static ObjectCacheFactory::makeLocalServerCache ( string $keyspace)
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.

Access: internal
For use by ServiceWiring and ExtensionRegistry. There are use cases whereby we want to build up local server cache without service wiring available.
Since
1.43, previously on ObjectCache.php since 1.35
Parameters
string$keyspace
Returns
BagOStuff

Definition at line 413 of file ObjectCacheFactory.php.

References $params.

◆ newFromParams()

ObjectCacheFactory::newFromParams ( array $params)

Create a new cache object from parameters specification supplied.

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.
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 198 of file ObjectCacheFactory.php.

References $params.

Member Data Documentation

◆ $localServerCacheClass

string ObjectCacheFactory::$localServerCacheClass
static
Access: internal
ObjectCacheFactoryTest only

Definition at line 103 of file ObjectCacheFactory.php.

◆ CONSTRUCTOR_OPTIONS

const ObjectCacheFactory::CONSTRUCTOR_OPTIONS
Initial value:
= [
MainConfigNames::SQLiteDataDir,
MainConfigNames::UpdateRowsPerQuery,
MainConfigNames::MemCachedServers,
MainConfigNames::MemCachedPersistent,
MainConfigNames::MemCachedTimeout,
MainConfigNames::CachePrefix,
MainConfigNames::ObjectCaches,
MainConfigNames::MainCacheType,
MainConfigNames::MessageCacheType,
MainConfigNames::ParserCacheType,
]
Access: internal
For use by ServiceWiring.php

Definition at line 78 of file ObjectCacheFactory.php.


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