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 !==
'' ) {
157 return WikiMap::getCurrentWikiDbDomain()->getId();
172 $params[
'logger'] = LoggerFactory::getInstance(
$params[
'loggroup'] ??
'objectcache' );
173 if ( !isset(
$params[
'keyspace'] ) ) {
174 $params[
'keyspace'] = self::getDefaultKeyspace();
176 if ( isset(
$params[
'factory'] ) ) {
178 } elseif ( isset(
$params[
'class'] ) ) {
181 $params[
'asyncHandler'] =
$params[
'asyncHandler'] ??
'DeferredUpdates::addCallableUpdate';
185 if ( is_a( $class, SqlBagOStuff::class,
true ) ) {
186 if ( isset(
$params[
'server'] ) && !isset(
$params[
'servers'] ) ) {
191 if ( isset(
$params[
'servers'] ) ) {
192 foreach (
$params[
'servers']
as &$server ) {
193 if ( $server[
'type'] ===
'sqlite' && !isset( $server[
'dbDirectory'] ) ) {
194 $server[
'dbDirectory'] = MediaWikiServices::getInstance()
195 ->getMainConfig()->get(
'SQLiteDataDir' );
202 if ( is_subclass_of( $class, MemcachedBagOStuff::class ) ) {
203 if ( !isset(
$params[
'servers'] ) ) {
206 if ( !isset(
$params[
'debug'] ) ) {
209 if ( !isset(
$params[
'persistent'] ) ) {
212 if ( !isset(
$params[
'timeout'] ) ) {
218 throw new InvalidArgumentException(
"The definition of cache type \""
219 . print_r(
$params,
true ) .
"\" lacks both "
220 .
"factory and class parameters." );
240 foreach ( $candidates
as $candidate ) {
242 $cache = self::getInstance( $candidate );
251 if ( MediaWikiServices::getInstance()->isServiceDisabled(
'DBLoadBalancer' ) ) {
259 return self::getInstance( $candidate );
280 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
303 throw new UnexpectedValueException(
304 "Cache type \"$id\" requested is not present in \$wgWANObjectCaches." );
309 throw new UnexpectedValueException(
310 "Cache type \"{$params['cacheId']}\" is not present in \$wgObjectCaches." );
314 return self::newWANCacheFromParams(
$params );
328 $services = MediaWikiServices::getInstance();
330 $erGroup =
$services->getEventRelayerGroup();
331 if ( isset(
$params[
'channels'] ) ) {
332 foreach (
$params[
'channels']
as $action => $channel ) {
333 $params[
'relayers'][$action] = $erGroup->getRelayer( $channel );
334 $params[
'channels'][$action] = $channel;
338 $params[
'logger'] = LoggerFactory::getInstance(
$params[
'loggroup'] ??
'objectcache' );
343 $params[
'asyncHandler'] = [ DeferredUpdates::class,
'addCallableUpdate' ];
370 return MediaWikiServices::getInstance()->getMainWANObjectCache();
393 return MediaWikiServices::getInstance()->getMainObjectStash();
400 self::$instances = [];
401 self::$wanInstances = [];
411 if ( function_exists(
'apc_fetch' ) ) {
413 } elseif ( function_exists(
'apcu_fetch' ) ) {
415 } elseif ( function_exists(
'wincache_ucache_get' ) ) {
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$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
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.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
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))