141 $services ??= MediaWikiServices::getInstance();
142 $conf = $services->getMainConfig();
146 'logger' => LoggerFactory::getInstance( $params[
'loggroup'] ??
'objectcache' ),
147 'keyspace' => self::getDefaultKeyspace(),
148 'asyncHandler' => [ DeferredUpdates::class,
'addCallableUpdate' ],
149 'reportDupes' =>
true,
150 'stats' => $services->getStatsdDataFactory(),
153 if ( isset( $params[
'factory'] ) ) {
154 $args = $params[
'args'] ?? [ $params ];
156 return call_user_func( $params[
'factory'], ...$args );
159 if ( !isset( $params[
'class'] ) ) {
160 throw new InvalidArgumentException(
161 'No "factory" nor "class" provided; got "' . print_r( $params,
true ) .
'"'
165 $class = $params[
'class'];
168 if ( is_a( $class, SqlBagOStuff::class,
true ) ) {
169 if ( isset( $params[
'globalKeyLB'] ) ) {
170 throw new InvalidArgumentException(
171 'globalKeyLB in $wgObjectCaches is no longer supported' );
173 if ( isset( $params[
'server'] ) && !isset( $params[
'servers'] ) ) {
174 $params[
'servers'] = [ $params[
'server'] ];
175 unset( $params[
'server'] );
177 if ( isset( $params[
'servers'] ) ) {
179 foreach ( $params[
'servers'] as &$server ) {
180 if ( $server[
'type'] ===
'sqlite' && !isset( $server[
'dbDirectory'] ) ) {
181 $server[
'dbDirectory'] = $conf->get( MainConfigNames::SQLiteDataDir );
184 } elseif ( isset( $params[
'cluster'] ) ) {
185 $cluster = $params[
'cluster'];
186 $params[
'loadBalancerCallback'] =
static function () use ( $services, $cluster ) {
187 return $services->getDBLoadBalancerFactory()->getExternalLB( $cluster );
189 $params += [
'dbDomain' => false ];
191 $params[
'loadBalancerCallback'] =
static function () use ( $services ) {
192 return $services->getDBLoadBalancer();
194 $params += [
'dbDomain' => false ];
196 $params += [
'writeBatchSize' => $conf->get( MainConfigNames::UpdateRowsPerQuery ) ];
200 if ( is_subclass_of( $class, MemcachedBagOStuff::class ) ) {
202 'servers' => $conf->get( MainConfigNames::MemCachedServers ),
203 'persistent' => $conf->get( MainConfigNames::MemCachedPersistent ),
204 'timeout' => $conf->get( MainConfigNames::MemCachedTimeout ),
209 if ( is_a( $class, MultiWriteBagOStuff::class,
true ) ) {
212 '@phan-var array{caches:array[]} $params';
213 foreach ( $params[
'caches'] ?? [] as $i => $cacheInfo ) {
216 $params[
'caches'][$i] = self::newFromParams( $cacheInfo, $services );
220 return new $class( $params );