67 public static $instances = [];
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 !==
'' ) {
141 $services = MediaWikiServices::getInstance();
144 'logger' => LoggerFactory::getInstance( $params[
'loggroup'] ??
'objectcache' ),
145 'keyspace' => self::getDefaultKeyspace(),
146 'asyncHandler' => [ DeferredUpdates::class,
'addCallableUpdate' ],
147 'reportDupes' =>
true,
150 if ( !isset( $params[
'stats'] ) ) {
151 $params[
'stats'] = $services->getStatsdDataFactory();
154 if ( isset( $params[
'factory'] ) ) {
155 $args = $params[
'args'] ?? [ $params ];
157 return call_user_func( $params[
'factory'], ...
$args );
160 if ( !isset( $params[
'class'] ) ) {
161 throw new InvalidArgumentException(
162 'No "factory" nor "class" provided; got "' . print_r( $params,
true ) .
'"'
166 $class = $params[
'class'];
167 $conf = $conf ?? $services->getMainConfig();
170 if ( is_a( $class, SqlBagOStuff::class,
true ) ) {
171 if ( isset( $params[
'globalKeyLB'] ) ) {
172 throw new InvalidArgumentException(
173 'globalKeyLB in $wgObjectCaches is no longer supported' );
175 if ( isset( $params[
'server'] ) && !isset( $params[
'servers'] ) ) {
176 $params[
'servers'] = [ $params[
'server'] ];
177 unset( $params[
'server'] );
179 if ( isset( $params[
'servers'] ) ) {
181 foreach ( $params[
'servers'] as &$server ) {
182 if ( $server[
'type'] ===
'sqlite' && !isset( $server[
'dbDirectory'] ) ) {
183 $server[
'dbDirectory'] = $conf->get( MainConfigNames::SQLiteDataDir );
186 } elseif ( isset( $params[
'cluster'] ) ) {
187 $cluster = $params[
'cluster'];
188 $params[
'loadBalancerCallback'] =
static function () use ( $services, $cluster ) {
189 return $services->getDBLoadBalancerFactory()->getExternalLB( $cluster );
191 $params += [
'dbDomain' => false ];
193 $params[
'loadBalancerCallback'] =
static function () use ( $services ) {
194 return $services->getDBLoadBalancer();
196 $params += [
'dbDomain' => false ];
198 $params += [
'writeBatchSize' => $conf->get( MainConfigNames::UpdateRowsPerQuery ) ];
202 if ( is_subclass_of( $class, MemcachedBagOStuff::class ) ) {
204 'servers' => $conf->get( MainConfigNames::MemCachedServers ),
205 'persistent' => $conf->get( MainConfigNames::MemCachedPersistent ),
206 'timeout' => $conf->get( MainConfigNames::MemCachedTimeout ),
210 return new $class( $params );
229 foreach ( $candidates as $candidate ) {
231 $cache = self::getInstance( $candidate );
240 if ( MediaWikiServices::getInstance()->isServiceDisabled(
'DBLoadBalancer' ) ) {
248 return self::getInstance( $candidate );
269 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
296 self::$instances = [];
315 'reportDupes' => false,
317 'keyspace' => self::getDefaultKeyspace(),
319 if ( function_exists(
'apcu_fetch' ) ) {
321 if ( PHP_SAPI !==
'cli' || ini_get(
'apc.enable_cli' ) ) {
324 } 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.