81 if ( !isset( self::$instances[$id] ) ) {
82 self::$instances[$id] = self::newFromId( $id );
85 return self::$instances[$id];
98 if ( !isset( self::$wanInstances[$id] ) ) {
99 self::$wanInstances[$id] = self::newWANCacheFromId( $id );
102 return self::$wanInstances[$id];
119 } elseif ( $id ===
'hash' ) {
123 throw new InvalidArgumentException(
"Invalid object cache type \"$id\" requested. " .
124 "It is not present in \$wgObjectCaches." );
143 if ( is_string( $keyspace ) && $keyspace !==
'' ) {
147 return WikiMap::getCurrentWikiDbDomain()->getId();
162 $params[
'logger'] = $params[
'logger'] ??
163 LoggerFactory::getInstance( $params[
'loggroup'] ??
'objectcache' );
164 if ( !isset( $params[
'keyspace'] ) ) {
165 $params[
'keyspace'] = self::getDefaultKeyspace();
167 if ( isset( $params[
'factory'] ) ) {
168 return call_user_func( $params[
'factory'], $params );
169 } elseif ( isset( $params[
'class'] ) ) {
170 $class = $params[
'class'];
172 $params[
'asyncHandler'] = $params[
'asyncHandler']
173 ?? [ DeferredUpdates::class,
'addCallableUpdate' ];
175 $params[
'reportDupes'] = $params[
'reportDupes'] ??
true;
177 if ( is_a( $class, SqlBagOStuff::class,
true ) ) {
178 if ( isset( $params[
'server'] ) && !isset( $params[
'servers'] ) ) {
179 $params[
'servers'] = [ $params[
'server'] ];
180 unset( $params[
'server'] );
183 if ( isset( $params[
'servers'] ) ) {
184 foreach ( $params[
'servers'] as &$server ) {
185 if ( $server[
'type'] ===
'sqlite' && !isset( $server[
'dbDirectory'] ) ) {
186 $server[
'dbDirectory'] = MediaWikiServices::getInstance()
187 ->getMainConfig()->get(
'SQLiteDataDir' );
194 if ( is_subclass_of( $class, MemcachedBagOStuff::class ) ) {
195 if ( !isset( $params[
'servers'] ) ) {
196 $params[
'servers'] =
$GLOBALS[
'wgMemCachedServers'];
198 if ( !isset( $params[
'persistent'] ) ) {
199 $params[
'persistent'] =
$GLOBALS[
'wgMemCachedPersistent'];
201 if ( !isset( $params[
'timeout'] ) ) {
202 $params[
'timeout'] =
$GLOBALS[
'wgMemCachedTimeout'];
205 return new $class( $params );
207 throw new InvalidArgumentException(
"The definition of cache type \""
208 . print_r( $params,
true ) .
"\" lacks both "
209 .
"factory and class parameters." );
229 foreach ( $candidates as $candidate ) {
231 $cache = self::getInstance( $candidate );
240 if ( MediaWikiServices::getInstance()->isServiceDisabled(
'DBLoadBalancer' ) ) {
248 return self::getInstance( $candidate );
269 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
292 throw new UnexpectedValueException(
293 "Cache type \"$id\" requested is not present in \$wgWANObjectCaches." );
298 throw new UnexpectedValueException(
299 "Cache type \"{$params['cacheId']}\" is not present in \$wgObjectCaches." );
303 return self::newWANCacheFromParams( $params );
321 $services = MediaWikiServices::getInstance();
322 $params[
'cache'] = self::newFromParams( $params[
'store'] );
323 $params[
'logger'] = LoggerFactory::getInstance( $params[
'loggroup'] ??
'objectcache' );
326 $params[
'stats'] = $services->getStatsdDataFactory();
328 $params[
'asyncHandler'] = [ DeferredUpdates::class,
'addCallableUpdate' ];
331 $class = $params[
'class'];
333 return new $class( $params );
352 self::$instances = [];
353 self::$wanInstances = [];
363 if ( function_exists(
'apcu_fetch' ) ) {
365 if ( PHP_SAPI !==
'cli' || ini_get(
'apc.enable_cli' ) ) {
368 } elseif ( function_exists(
'apc_fetch' ) ) {
370 if ( PHP_SAPI !==
'cli' || ini_get(
'apc.enable_cli' ) ) {
373 } elseif ( function_exists(
'wincache_ucache_get' ) ) {
$wgObjectCaches
Advanced object cache configuration.
$wgParserCacheType
The cache type for storing article HTML.
$wgMainCacheType
Main cache type.
$wgSecretKey
This should always be customised in LocalSettings.php.
$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
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
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 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.