76 if ( !isset( self::$instances[$id] ) ) {
77 self::$instances[$id] = self::newFromId( $id );
80 return self::$instances[$id];
90 private static function newFromId( $id ) {
101 throw new InvalidArgumentException(
"Invalid object cache type \"$id\" requested. " .
102 "It is not present in \$wgObjectCaches." );
117 private static function getDefaultKeyspace() {
121 if ( is_string( $keyspace ) && $keyspace !==
'' ) {
140 $services = MediaWikiServices::getInstance();
143 'logger' => LoggerFactory::getInstance( $params[
'loggroup'] ??
'objectcache' ),
144 'keyspace' => self::getDefaultKeyspace(),
145 'asyncHandler' => [ DeferredUpdates::class,
'addCallableUpdate' ],
146 'reportDupes' =>
true,
147 'stats' => $services->getStatsdDataFactory(),
150 if ( isset( $params[
'factory'] ) ) {
151 $args = $params[
'args'] ?? [ $params ];
153 return call_user_func( $params[
'factory'], ...$args );
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 ??= $services->getMainConfig();
166 if ( is_a( $class, SqlBagOStuff::class,
true ) ) {
167 if ( isset( $params[
'globalKeyLB'] ) ) {
168 throw new InvalidArgumentException(
169 'globalKeyLB in $wgObjectCaches is no longer supported' );
171 if ( isset( $params[
'server'] ) && !isset( $params[
'servers'] ) ) {
172 $params[
'servers'] = [ $params[
'server'] ];
173 unset( $params[
'server'] );
175 if ( isset( $params[
'servers'] ) ) {
177 foreach ( $params[
'servers'] as &$server ) {
178 if ( $server[
'type'] ===
'sqlite' && !isset( $server[
'dbDirectory'] ) ) {
179 $server[
'dbDirectory'] = $conf->get( MainConfigNames::SQLiteDataDir );
182 } elseif ( isset( $params[
'cluster'] ) ) {
183 $cluster = $params[
'cluster'];
184 $params[
'loadBalancerCallback'] =
static function () use ( $services, $cluster ) {
185 return $services->getDBLoadBalancerFactory()->getExternalLB( $cluster );
187 $params += [
'dbDomain' => false ];
189 $params[
'loadBalancerCallback'] =
static function () use ( $services ) {
190 return $services->getDBLoadBalancer();
192 $params += [
'dbDomain' => false ];
194 $params += [
'writeBatchSize' => $conf->get( MainConfigNames::UpdateRowsPerQuery ) ];
198 if ( is_subclass_of( $class, MemcachedBagOStuff::class ) ) {
200 'servers' => $conf->get( MainConfigNames::MemCachedServers ),
201 'persistent' => $conf->get( MainConfigNames::MemCachedPersistent ),
202 'timeout' => $conf->get( MainConfigNames::MemCachedTimeout ),
207 if ( is_a( $class, MultiWriteBagOStuff::class,
true ) ) {
210 '@phan-var array{caches:array[]} $params';
211 foreach ( $params[
'caches'] ?? [] as $i => $cacheInfo ) {
218 return new $class( $params );
237 foreach ( $candidates as $candidate ) {
248 if ( MediaWikiServices::getInstance()->isServiceDisabled(
'DBLoadBalancer' ) ) {
277 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
304 self::$instances = [];
323 'reportDupes' => false,
325 'keyspace' => self::getDefaultKeyspace(),
327 if ( function_exists(
'apcu_fetch' ) ) {
329 if ( PHP_SAPI !==
'cli' || ini_get(
'apc.enable_cli' ) ) {
332 } elseif ( function_exists(
'wincache_ucache_get' ) ) {
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.
A class containing constants representing the names of configuration variables.
Functions to get cache objects.
static getLocalServerInstance( $fallback=CACHE_NONE)
Factory function for CACHE_ACCEL (referenced from configuration)
static makeLocalServerCache()
Create a new BagOStuff instance for local-server caching.
static newAnything( $params)
Factory function for CACHE_ANYTHING (referenced by configuration)
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.
static getCurrentWikiDbDomain()
Wrapper for WinCache object caching functions; identical interface to the APC wrapper.
$wgObjectCaches
Config variable stub for the ObjectCaches setting, for use by phpdoc and IDEs.
$wgParserCacheType
Config variable stub for the ParserCacheType setting, for use by phpdoc and IDEs.
$wgMainCacheType
Config variable stub for the MainCacheType setting, for use by phpdoc and IDEs.
$wgCachePrefix
Config variable stub for the CachePrefix setting, for use by phpdoc and IDEs.
$wgMessageCacheType
Config variable stub for the MessageCacheType setting, for use by phpdoc and IDEs.
Interface for configuration instances.