66 public static $instances = [];
75 if ( !isset( self::$instances[$id] ) ) {
76 self::$instances[$id] = self::newFromId( $id );
79 return self::$instances[$id];
96 } elseif ( $id ===
'hash' ) {
100 throw new InvalidArgumentException(
"Invalid object cache type \"$id\" requested. " .
101 "It is not present in \$wgObjectCaches." );
120 if ( is_string( $keyspace ) && $keyspace !==
'' ) {
124 return WikiMap::getCurrentWikiDbDomain()->getId();
142 'logger' => LoggerFactory::getInstance( $params[
'loggroup'] ??
'objectcache' ),
143 'keyspace' => self::getDefaultKeyspace(),
144 'asyncHandler' => [ DeferredUpdates::class,
'addCallableUpdate' ],
145 'reportDupes' =>
true,
148 if ( !isset( $params[
'stats'] ) ) {
149 $params[
'stats'] = MediaWikiServices::getInstance()->getStatsdDataFactory();
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' =>
static function () {
181 return MediaWikiServices::getInstance()->getDBLoadBalancer();
185 $params += [
'writeBatchSize' => $conf->get(
'UpdateRowsPerQuery' ) ];
189 if ( is_subclass_of( $class, MemcachedBagOStuff::class ) ) {
191 'servers' => $conf->get(
'MemCachedServers' ),
192 'persistent' => $conf->get(
'MemCachedPersistent' ),
193 'timeout' => $conf->get(
'MemCachedTimeout' ),
197 return new $class( $params );
216 foreach ( $candidates as $candidate ) {
218 $cache = self::getInstance( $candidate );
227 if ( MediaWikiServices::getInstance()->isServiceDisabled(
'DBLoadBalancer' ) ) {
235 return self::getInstance( $candidate );
256 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
283 self::$instances = [];
302 'reportDupes' => false,
306 if ( function_exists(
'apcu_fetch' ) ) {
308 if ( PHP_SAPI !==
'cli' || ini_get(
'apc.enable_cli' ) ) {
311 } 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.
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 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.