93 if ( !isset( self::$instances[$id] ) ) {
94 self::$instances[$id] = self::newFromId( $id );
97 return self::$instances[$id];
108 if ( !isset( self::$wanInstances[$id] ) ) {
109 self::$wanInstances[$id] = self::newWANCacheFromId( $id );
112 return self::$wanInstances[$id];
129 } elseif ( $id ===
'hash' ) {
133 throw new InvalidArgumentException(
"Invalid object cache type \"$id\" requested. " .
134 "It is not present in \$wgObjectCaches." );
153 if ( is_string( $keyspace ) && $keyspace !==
'' ) {
172 if ( isset(
$params[
'loggroup'] ) ) {
173 $params[
'logger'] = LoggerFactory::getInstance(
$params[
'loggroup'] );
175 $params[
'logger'] = LoggerFactory::getInstance(
'objectcache' );
177 if ( !isset(
$params[
'keyspace'] ) ) {
178 $params[
'keyspace'] = self::getDefaultKeyspace();
180 if ( isset(
$params[
'factory'] ) ) {
182 } elseif ( isset(
$params[
'class'] ) ) {
187 :
'DeferredUpdates::addCallableUpdate';
193 if ( is_a( $class, SqlBagOStuff::class,
true ) ) {
194 if ( isset(
$params[
'server'] ) && !isset(
$params[
'servers'] ) ) {
199 if ( isset(
$params[
'servers'] ) ) {
200 foreach (
$params[
'servers'] as &$server ) {
201 if ( $server[
'type'] ===
'sqlite' && !isset( $server[
'dbDirectory'] ) ) {
202 $server[
'dbDirectory'] = MediaWikiServices::getInstance()
203 ->getMainConfig()->get(
'SQLiteDataDir' );
210 if ( is_subclass_of( $class, MemcachedBagOStuff::class ) ) {
211 if ( !isset(
$params[
'servers'] ) ) {
214 if ( !isset(
$params[
'debug'] ) ) {
217 if ( !isset(
$params[
'persistent'] ) ) {
220 if ( !isset(
$params[
'timeout'] ) ) {
226 throw new InvalidArgumentException(
"The definition of cache type \""
227 . print_r(
$params,
true ) .
"\" lacks both "
228 .
"factory and class parameters." );
248 foreach ( $candidates as $candidate ) {
251 $cache = self::getInstance( $candidate );
260 if ( MediaWikiServices::getInstance()->isServiceDisabled(
'DBLoadBalancer' ) ) {
268 return self::getInstance( $candidate );
289 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
312 throw new UnexpectedValueException(
313 "Cache type \"$id\" requested is not present in \$wgWANObjectCaches." );
318 throw new UnexpectedValueException(
319 "Cache type \"{$params['cacheId']}\" is not present in \$wgObjectCaches." );
323 return self::newWANCacheFromParams(
$params );
337 $services = MediaWikiServices::getInstance();
339 $erGroup =
$services->getEventRelayerGroup();
340 foreach (
$params[
'channels'] as $action => $channel ) {
341 $params[
'relayers'][$action] = $erGroup->getRelayer( $channel );
342 $params[
'channels'][$action] = $channel;
345 if ( isset(
$params[
'loggroup'] ) ) {
346 $params[
'logger'] = LoggerFactory::getInstance(
$params[
'loggroup'] );
348 $params[
'logger'] = LoggerFactory::getInstance(
'objectcache' );
354 $params[
'asyncHandler'] = [ DeferredUpdates::class,
'addCallableUpdate' ];
381 return MediaWikiServices::getInstance()->getMainWANObjectCache();
404 return MediaWikiServices::getInstance()->getMainObjectStash();
411 self::$instances = [];
412 self::$wanInstances = [];
$wgObjectCaches
Advanced object cache configuration.
$wgParserCacheType
The cache type for storing article HTML.
$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
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
interface is intended to be more or less compatible with the PHP memcached client.
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 getMainWANInstance()
Get the main WAN cache object.
static getMainStashInstance()
Get the cache object for the main stash.
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 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.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
CACHE_MEMCACHED $wgMainCacheType