70 public static $instances = [];
79 if ( !isset( self::$instances[$id] ) ) {
80 self::$instances[$id] = self::newFromId( $id );
83 return self::$instances[$id];
100 } elseif ( $id ===
'hash' ) {
104 throw new InvalidArgumentException(
"Invalid object cache type \"$id\" requested. " .
105 "It is not present in \$wgObjectCaches." );
124 if ( is_string( $keyspace ) && $keyspace !==
'' ) {
128 return WikiMap::getCurrentWikiDbDomain()->getId();
146 'logger' => LoggerFactory::getInstance( $params[
'loggroup'] ??
'objectcache' ),
147 'keyspace' => self::getDefaultKeyspace(),
148 'asyncHandler' => [ DeferredUpdates::class,
'addCallableUpdate' ],
149 'reportDupes' =>
true,
152 if ( isset( $params[
'factory'] ) ) {
153 return call_user_func( $params[
'factory'], $params );
156 if ( !isset( $params[
'class'] ) ) {
157 throw new InvalidArgumentException(
158 'No "factory" nor "class" provided; got "' . print_r( $params,
true ) .
'"'
162 $class = $params[
'class'];
163 $conf = $conf ?? MediaWikiServices::getInstance()->getMainConfig();
166 if ( is_a( $class, SqlBagOStuff::class,
true ) ) {
167 if ( isset( $params[
'server'] ) && !isset( $params[
'servers'] ) ) {
168 $params[
'servers'] = [ $params[
'server'] ];
169 unset( $params[
'server'] );
172 if ( isset( $params[
'servers'] ) ) {
173 foreach ( $params[
'servers'] as &$server ) {
174 if ( $server[
'type'] ===
'sqlite' && !isset( $server[
'dbDirectory'] ) ) {
175 $server[
'dbDirectory'] = $conf->get(
'SQLiteDataDir' );
178 } elseif ( !isset( $params[
'localKeyLB'] ) ) {
179 $params[
'localKeyLB'] = [
180 'factory' =>
function () {
181 return MediaWikiServices::getInstance()->getDBLoadBalancer();
188 if ( is_subclass_of( $class, MemcachedBagOStuff::class ) ) {
190 'servers' => $conf->get(
'MemCachedServers' ),
191 'persistent' => $conf->get(
'MemCachedPersistent' ),
192 'timeout' => $conf->get(
'MemCachedTimeout' ),
196 return new $class( $params );
215 foreach ( $candidates as $candidate ) {
217 $cache = self::getInstance( $candidate );
226 if ( MediaWikiServices::getInstance()->isServiceDisabled(
'DBLoadBalancer' ) ) {
234 return self::getInstance( $candidate );
255 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
282 self::$instances = [];
301 'reportDupes' => false,
305 if ( function_exists(
'apcu_fetch' ) ) {
307 if ( PHP_SAPI !==
'cli' || ini_get(
'apc.enable_cli' ) ) {
310 } elseif ( function_exists(
'wincache_ucache_get' ) ) {
328 if ( function_exists(
'apcu_fetch' ) ) {
330 if ( PHP_SAPI !==
'cli' || ini_get(
'apc.enable_cli' ) ) {
333 } elseif ( function_exists(
'wincache_ucache_get' ) ) {
$wgObjectCaches
Advanced object cache configuration.
$wgParserCacheType
The cache type for storing article HTML.
$wgMainCacheType
Main cache type.
$wgCachePrefix
Overwrite the caching key prefix with custom value.
$wgMessageCacheType
The cache type for storing the contents of the MediaWiki namespace.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
This is a wrapper for APCU's shared memory functions.
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 getLocalServerInstance( $fallback=CACHE_NONE)
Factory function for CACHE_ACCEL (referenced from DefaultSettings.php)
static makeLocalServerCache()
Create a new BagOStuff instance for local-server caching.
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 BagOStuff[] $instances
Map of (id => BagOStuff)
static detectLocalServerCache()
Detects which local server cache library is present and returns a configuration for it.
static newFromParams(array $params, Config $conf=null)
Create a new cache object from parameters.
static getInstance( $id)
Get a cached instance of the specified type of cache object.
static getLocalClusterInstance()
Get the main cluster-local cache object.
Wrapper for WinCache object caching functions; identical interface to the APC wrapper.
Interface for configuration instances.