Go to the documentation of this file.
81 if ( !isset( self::$instances[$id] ) ) {
85 return self::$instances[$id];
98 if ( !isset( self::$wanInstances[$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 !==
'' ) {
162 $params[
'logger'] = $params[
'logger'] ??
163 LoggerFactory::getInstance( $params[
'loggroup'] ??
'objectcache' );
164 if ( !isset( $params[
'keyspace'] ) ) {
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 ) {
240 if ( MediaWikiServices::getInstance()->isServiceDisabled(
'DBLoadBalancer' ) ) {
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." );
321 $services = MediaWikiServices::getInstance();
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' ) ) {
static clear()
Clear all the cached instances.
static newFromId( $id)
Create a new cache object of the specified type.
Functions to get cache objects.
static getCurrentWikiDbDomain()
static getLocalClusterInstance()
Get the main cluster-local cache object.
Simple store for keeping values in an associative array for the current process.
A BagOStuff object with no objects in it.
static detectLocalServerCache()
Detects which local server cache library is present and returns a configuration for it.
$wgWANObjectCaches
Advanced WAN object cache configuration.
static BagOStuff[] $instances
Map of (id => BagOStuff)
$wgMessageCacheType
The cache type for storing the contents of the MediaWiki namespace.
Class representing a cache/ephemeral data store.
static newAnything( $params)
Factory function for CACHE_ANYTHING (referenced from DefaultSettings.php)
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
$wgMainCacheType
Main cache type.
static WANObjectCache[] $wanInstances
Map of (id => WANObjectCache)
$wgCachePrefix
Overwrite the caching key prefix with custom value.
global $wgCommandLineMode
static newWANCacheFromParams(array $params)
Create a new cache object of the specified type.
$wgObjectCaches
Advanced object cache configuration.
static getWANInstance( $id)
Get a cached instance of the specified type of WAN cache object.
static getInstance( $id)
Get a cached instance of the specified type of cache object.
$wgParserCacheType
The cache type for storing article HTML.
static newWANCacheFromId( $id)
Create a new cache object of the specified type.
Multi-datacenter aware caching interface.
static getDefaultKeyspace()
Get the default keyspace for this wiki.
static newFromParams( $params)
Create a new cache object from parameters.
$wgSecretKey
This should always be customised in LocalSettings.php.
static getLocalServerInstance( $fallback=CACHE_NONE)
Factory function for CACHE_ACCEL (referenced from DefaultSettings.php)