93 if ( !isset( self::$instances[$id] ) ) {
94 self::$instances[$id] = self::newFromId( $id );
97 return self::$instances[$id];
108 if ( !isset( self::$wanInstances[$id] ) ) {
109 self::$wanInstances[$id] = self::newWANCacheFromId( $id );
112 return self::$wanInstances[$id];
129 } elseif ( $id ===
'hash' ) {
133 throw new InvalidArgumentException(
"Invalid object cache type \"$id\" requested. " .
134 "It is not present in \$wgObjectCaches." );
153 if ( is_string( $keyspace ) && $keyspace !==
'' ) {
172 if ( isset(
$params[
'loggroup'] ) ) {
173 $params[
'logger'] = LoggerFactory::getInstance(
$params[
'loggroup'] );
175 $params[
'logger'] = LoggerFactory::getInstance(
'objectcache' );
177 if ( !isset(
$params[
'keyspace'] ) ) {
178 $params[
'keyspace'] = self::getDefaultKeyspace();
180 if ( isset(
$params[
'factory'] ) ) {
182 } elseif ( isset(
$params[
'class'] ) ) {
185 $params[
'asyncHandler'] =
$params[
'asyncHandler'] ??
'DeferredUpdates::addCallableUpdate';
189 if ( is_a( $class, SqlBagOStuff::class,
true ) ) {
190 if ( isset(
$params[
'server'] ) && !isset(
$params[
'servers'] ) ) {
195 if ( isset(
$params[
'servers'] ) ) {
196 foreach (
$params[
'servers'] as &$server ) {
197 if ( $server[
'type'] ===
'sqlite' && !isset( $server[
'dbDirectory'] ) ) {
198 $server[
'dbDirectory'] = MediaWikiServices::getInstance()
199 ->getMainConfig()->get(
'SQLiteDataDir' );
206 if ( is_subclass_of( $class, MemcachedBagOStuff::class ) ) {
207 if ( !isset(
$params[
'servers'] ) ) {
210 if ( !isset(
$params[
'debug'] ) ) {
213 if ( !isset(
$params[
'persistent'] ) ) {
216 if ( !isset(
$params[
'timeout'] ) ) {
222 throw new InvalidArgumentException(
"The definition of cache type \""
223 . print_r(
$params,
true ) .
"\" lacks both "
224 .
"factory and class parameters." );
244 foreach ( $candidates as $candidate ) {
247 $cache = self::getInstance( $candidate );
256 if ( MediaWikiServices::getInstance()->isServiceDisabled(
'DBLoadBalancer' ) ) {
264 return self::getInstance( $candidate );
285 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
308 throw new UnexpectedValueException(
309 "Cache type \"$id\" requested is not present in \$wgWANObjectCaches." );
314 throw new UnexpectedValueException(
315 "Cache type \"{$params['cacheId']}\" is not present in \$wgObjectCaches." );
319 return self::newWANCacheFromParams(
$params );
333 $services = MediaWikiServices::getInstance();
335 $erGroup =
$services->getEventRelayerGroup();
336 if ( isset(
$params[
'channels'] ) ) {
337 foreach (
$params[
'channels'] as $action => $channel ) {
338 $params[
'relayers'][$action] = $erGroup->getRelayer( $channel );
339 $params[
'channels'][$action] = $channel;
343 if ( isset(
$params[
'loggroup'] ) ) {
344 $params[
'logger'] = LoggerFactory::getInstance(
$params[
'loggroup'] );
346 $params[
'logger'] = LoggerFactory::getInstance(
'objectcache' );
352 $params[
'asyncHandler'] = [ DeferredUpdates::class,
'addCallableUpdate' ];
379 return MediaWikiServices::getInstance()->getMainWANObjectCache();
402 return MediaWikiServices::getInstance()->getMainObjectStash();
409 self::$instances = [];
410 self::$wanInstances = [];
420 if ( function_exists(
'apc_fetch' ) ) {
422 } elseif ( function_exists(
'apcu_fetch' ) ) {
424 } elseif ( function_exists(
'wincache_ucache_get' ) ) {
$wgObjectCaches
Advanced object cache configuration.
$wgParserCacheType
The cache type for storing article HTML.
$wgCachePrefix
Overwrite the caching key prefix with custom value.
$wgMessageCacheType
The cache type for storing the contents of the MediaWiki namespace.
$wgWANObjectCaches
Advanced WAN object cache configuration.
global $wgCommandLineMode
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Class representing a cache/ephemeral data store.
A BagOStuff object with no objects in it.
Simple store for keeping values in an associative array for the current process.
Functions to get cache objects.
static getWANInstance( $id)
Get a cached instance of the specified type of WAN cache object.
static getLocalServerInstance( $fallback=CACHE_NONE)
Factory function for CACHE_ACCEL (referenced from DefaultSettings.php)
static getMainWANInstance()
Get the main WAN cache object.
static getMainStashInstance()
Get the cache object for the main stash.
static newFromId( $id)
Create a new cache object of the specified type.
static newAnything( $params)
Factory function for CACHE_ANYTHING (referenced from DefaultSettings.php)
static getDefaultKeyspace()
Get the default keyspace for this wiki.
static clear()
Clear all the cached instances.
static newWANCacheFromId( $id)
Create a new cache object of the specified type.
static BagOStuff[] $instances
Map of (id => BagOStuff)
static newWANCacheFromParams(array $params)
Create a new cache object of the specified type.
static WANObjectCache[] $wanInstances
Map of (id => WANObjectCache)
static detectLocalServerCache()
Detects which local server cache library is present and returns a configuration for it.
static getInstance( $id)
Get a cached instance of the specified type of cache object.
static newFromParams( $params)
Create a new cache object from parameters.
static getLocalClusterInstance()
Get the main cluster-local cache object.
Multi-datacenter aware caching interface.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
CACHE_MEMCACHED $wgMainCacheType
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))