Manual:$wgObjectCaches

From mediawiki.org
Cache: $wgObjectCaches
Advanced object cache configuration.
Introduced in version:1.18.0 (r83140)
Removed in version:still in use
Allowed values:(array)
Default value:see below

Details[edit]

Advanced object cache configuration.

Use this to define the class names and constructor parameters which are used for the various cache types. Custom cache types may be defined here and referenced from $wgMainCacheType , $wgMessageCacheType or $wgParserCacheType .

The format is an associative array where the key is a cache identifier, and the value is an associative array of parameters. The "class" parameter is the class name which will be used. Alternatively, a "factory" parameter may be given, giving a callable function which will generate a suitable cache object.

Custom cache types[edit]

You can also create other cache configurations in addition to the built in CACHE_ constants by adding them. For example, to use redis as your cache (which does not have a built in CACHE_XXX constant) you can do:

$wgObjectCaches['redis'] = [
	'class' => 'RedisBagOStuff',
	'servers' => [
		'127.0.0.1:6379'
	],
	'password' => 'Your-Redis-password', // Highly recommended, otherwise comment out this line.
	'persistent' => true,
];
$wgMainCacheType = 'redis';

The MediaWiki-Vagrant appliance runs a redis service and with this configuration.

Default value[edit]

The 'slaveOnly' option for SqlBagOStuff (deprecated in 1.34), was removed. Use 'replicaOnly' instead.

MediaWiki version:
1.42
$wgObjectCaches = [
	CACHE_NONE => [ 'class' => EmptyBagOStuff::class, 'reportDupes' => false ],
	CACHE_DB => [ 'class' => SqlBagOStuff::class, 'loggroup' => 'SQLBagOStuff' ],

	CACHE_ANYTHING => [ 'factory' => 'ObjectCache::newAnything' ],
	CACHE_ACCEL => [ 'factory' => 'ObjectCache::getLocalServerInstance' ],

	'memcached-php' => [ 'class' => MemcachedPhpBagOStuff::class, 'loggroup' => 'memcached' ],
	'memcached-pecl' => [ 'class' => MemcachedPeclBagOStuff::class, 'loggroup' => 'memcached' ],
	'hash' => [ 'class' => HashBagOStuff::class, 'reportDupes' => false ],

	// Deprecated since 1.35.
	// - To configure a wg*CacheType variable to use the local server cache,
	//   use CACHE_ACCEL instead, which will select these automatically.
	// - To access the object for the local server cache at run-time,
	//   use MediaWikiServices::getLocalServerObjectCache()
	//   instead of e.g. ObjectCache::getInstance( 'apcu' ).
	// - To instantiate a new one of these explicitly, do so directly
	//   by using `new APCUBagOStuff( [ … ] )`
	// - To instantiate a new one of these including auto-detection and fallback,
	//   use ObjectCache::makeLocalServerCache().
	'apc' => [ 'class' => APCUBagOStuff::class, 'reportDupes' => false ],
	'apcu' => [ 'class' => APCUBagOStuff::class, 'reportDupes' => false ],
	'wincache' => [ 'class' => WinCacheBagOStuff::class, 'reportDupes' => false ],
];
MediaWiki versions:
1.38 – 1.41
$wgObjectCaches = [
	CACHE_NONE => [ 'class' => EmptyBagOStuff::class, 'reportDupes' => false ],
	CACHE_DB => [ 'class' => SqlBagOStuff::class, 'loggroup' => 'SQLBagOStuff' ],

	CACHE_ANYTHING => [ 'factory' => 'ObjectCache::newAnything' ],
	CACHE_ACCEL => [ 'factory' => 'ObjectCache::getLocalServerInstance' ],

	'db-replicated' => [
		'class'        => ReplicatedBagOStuff::class,
		'readFactory'  => [
			'factory' => 'ObjectCache::newFromParams',
			'args'    => [ [ 'class' => SqlBagOStuff::class, 'replicaOnly' => true ] ]
		],
		'writeFactory' => [
			'factory' => 'ObjectCache::newFromParams',
			'args'    => [ [ 'class' => SqlBagOStuff::class, 'replicaOnly' => false ] ]
		],
		'loggroup'     => 'SQLBagOStuff',
		'reportDupes'  => false
	],
	'memcached-php' => [ 'class' => MemcachedPhpBagOStuff::class, 'loggroup' => 'memcached' ],
	'memcached-pecl' => [ 'class' => MemcachedPeclBagOStuff::class, 'loggroup' => 'memcached' ],
	'hash' => [ 'class' => HashBagOStuff::class, 'reportDupes' => false ],

	// Deprecated since 1.35.
	// - To configure a wg*CacheType variable to use the local server cache,
	//   use CACHE_ACCEL instead, which will select these automatically.
	// - To access the object for the local server cache at run-time,
	//   use MediaWikiServices::getLocalServerObjectCache()
	//   instead of e.g. ObjectCache::getInstance( 'apcu' ).
	// - To instantiate a new one of these explicitly, do so directly
	//   by using `new APCUBagOStuff( [ … ] )`
	// - To instantiate a new one of these including auto-detection and fallback,
	//   use ObjectCache::makeLocalServerCache().
	'apc' => [ 'class' => APCUBagOStuff::class, 'reportDupes' => false ],
	'apcu' => [ 'class' => APCUBagOStuff::class, 'reportDupes' => false ],
	'wincache' => [ 'class' => WinCacheBagOStuff::class, 'reportDupes' => false ],
];
MediaWiki versions:
1.35 – 1.37
$wgObjectCaches = [
	CACHE_NONE => [ 'class' => EmptyBagOStuff::class, 'reportDupes' => false ],
	CACHE_DB => [ 'class' => SqlBagOStuff::class, 'loggroup' => 'SQLBagOStuff' ],

	CACHE_ANYTHING => [ 'factory' => 'ObjectCache::newAnything' ],
	CACHE_ACCEL => [ 'factory' => 'ObjectCache::getLocalServerInstance' ],
	CACHE_MEMCACHED => [ 'class' => MemcachedPhpBagOStuff::class, 'loggroup' => 'memcached' ],

	'db-replicated' => [
		'class'        => ReplicatedBagOStuff::class,
		'readFactory'  => [
			'factory' => 'ObjectCache::newFromParams',
			'args'    => [ [ 'class' => SqlBagOStuff::class, 'replicaOnly' => true ] ]
		],
		'writeFactory' => [
			'factory' => 'ObjectCache::newFromParams',
			'args'    => [ [ 'class' => SqlBagOStuff::class, 'replicaOnly' => false ] ]
		],
		'loggroup'     => 'SQLBagOStuff',
		'reportDupes'  => false
	],
	'memcached-php' => [ 'class' => MemcachedPhpBagOStuff::class, 'loggroup' => 'memcached' ],
	'memcached-pecl' => [ 'class' => MemcachedPeclBagOStuff::class, 'loggroup' => 'memcached' ],
	'hash' => [ 'class' => HashBagOStuff::class, 'reportDupes' => false ],

	// Deprecated since 1.35.
	// - To configure a wg*CacheType variable to use the local server cache,
	//   use CACHE_ACCEL instead, which will select these automatically.
	// - To access the object for the local server cache at run-time,
	//   use MediaWikiServices::getLocalServerObjectCache()
	//   instead of e.g. ObjectCache::getInstance( 'apcu' ).
	// - To instantiate a new one of these explicitly, do so directly
	//   by using `new APCUBagOStuff( [ … ] )`
	// - To instantiate a new one of these including auto-detection and fallback,
	//   use ObjectCache::makeLocalServerCache().
	'apc' => [ 'class' => APCUBagOStuff::class, 'reportDupes' => false ],
	'apcu' => [ 'class' => APCUBagOStuff::class, 'reportDupes' => false ],
	'wincache' => [ 'class' => WinCacheBagOStuff::class, 'reportDupes' => false ],
];
MediaWiki version:
1.34
$wgObjectCaches = [
	CACHE_NONE => [ 'class' => EmptyBagOStuff::class, 'reportDupes' => false ],
	CACHE_DB => [ 'class' => SqlBagOStuff::class, 'loggroup' => 'SQLBagOStuff' ],

	CACHE_ANYTHING => [ 'factory' => 'ObjectCache::newAnything' ],
	CACHE_ACCEL => [ 'factory' => 'ObjectCache::getLocalServerInstance' ],
	CACHE_MEMCACHED => [ 'class' => MemcachedPhpBagOStuff::class, 'loggroup' => 'memcached' ],

	'db-replicated' => [
		'class'       => ReplicatedBagOStuff::class,
		'readFactory' => [
			'class' => SqlBagOStuff::class,
			'args'  => [ [ 'replicaOnly' => true ] ]
		],
		'writeFactory' => [
			'class' => SqlBagOStuff::class,
			'args'  => [ [ 'replicaOnly' => false ] ]
		],
		'loggroup'  => 'SQLBagOStuff',
		'reportDupes' => false
	],

	'apc' => [ 'class' => APCBagOStuff::class, 'reportDupes' => false ],
	'apcu' => [ 'class' => APCUBagOStuff::class, 'reportDupes' => false ],
	'wincache' => [ 'class' => WinCacheBagOStuff::class, 'reportDupes' => false ],
	'memcached-php' => [ 'class' => MemcachedPhpBagOStuff::class, 'loggroup' => 'memcached' ],
	'memcached-pecl' => [ 'class' => MemcachedPeclBagOStuff::class, 'loggroup' => 'memcached' ],
	'hash' => [ 'class' => HashBagOStuff::class, 'reportDupes' => false ],
];
MediaWiki versions:
1.31 – 1.33
$wgObjectCaches = [
	CACHE_NONE => [ 'class' => EmptyBagOStuff::class, 'reportDupes' => false ],
	CACHE_DB => [ 'class' => SqlBagOStuff::class, 'loggroup' => 'SQLBagOStuff' ],

	CACHE_ANYTHING => [ 'factory' => 'ObjectCache::newAnything' ],
	CACHE_ACCEL => [ 'factory' => 'ObjectCache::getLocalServerInstance' ],
	CACHE_MEMCACHED => [ 'class' => MemcachedPhpBagOStuff::class, 'loggroup' => 'memcached' ],

	'db-replicated' => [
		'class'       => ReplicatedBagOStuff::class,
		'readFactory' => [
			'class' => SqlBagOStuff::class,
			'args'  => [ [ 'slaveOnly' => true ] ]
		],
		'writeFactory' => [
			'class' => SqlBagOStuff::class,
			'args'  => [ [ 'slaveOnly' => false ] ]
		],
		'loggroup'  => 'SQLBagOStuff',
		'reportDupes' => false
	],

	'apc' => [ 'class' => APCBagOStuff::class, 'reportDupes' => false ],
	'apcu' => [ 'class' => APCUBagOStuff::class, 'reportDupes' => false ],
	'wincache' => [ 'class' => WinCacheBagOStuff::class, 'reportDupes' => false ],
	'memcached-php' => [ 'class' => MemcachedPhpBagOStuff::class, 'loggroup' => 'memcached' ],
	'memcached-pecl' => [ 'class' => MemcachedPeclBagOStuff::class, 'loggroup' => 'memcached' ],
	'hash' => [ 'class' => HashBagOStuff::class, 'reportDupes' => false ],
];
MediaWiki versions:
1.28 – 1.30
$wgObjectCaches = [
	CACHE_NONE => [ 'class' => 'EmptyBagOStuff', 'reportDupes' => false ],
	CACHE_DB => [ 'class' => 'SqlBagOStuff', 'loggroup' => 'SQLBagOStuff' ],

	CACHE_ANYTHING => [ 'factory' => 'ObjectCache::newAnything' ],
	CACHE_ACCEL => [ 'factory' => 'ObjectCache::getLocalServerInstance' ],
	CACHE_MEMCACHED => [ 'class' => 'MemcachedPhpBagOStuff', 'loggroup' => 'memcached' ],

	'db-replicated' => [
		'class'       => 'ReplicatedBagOStuff',
		'readFactory' => [
			'class' => 'SqlBagOStuff',
			'args'  => [ [ 'slaveOnly' => true ] ]
		],
		'writeFactory' => [
			'class' => 'SqlBagOStuff',
			'args'  => [ [ 'slaveOnly' => false ] ]
		],
		'loggroup'  => 'SQLBagOStuff',
		'reportDupes' => false
	],

	'apc' => [ 'class' => 'APCBagOStuff', 'reportDupes' => false ],
	'apcu' => [ 'class' => 'APCUBagOStuff', 'reportDupes' => false ],
	'xcache' => [ 'class' => 'XCacheBagOStuff', 'reportDupes' => false ],
	'wincache' => [ 'class' => 'WinCacheBagOStuff', 'reportDupes' => false ],
	'memcached-php' => [ 'class' => 'MemcachedPhpBagOStuff', 'loggroup' => 'memcached' ],
	'memcached-pecl' => [ 'class' => 'MemcachedPeclBagOStuff', 'loggroup' => 'memcached' ],
	'hash' => [ 'class' => 'HashBagOStuff', 'reportDupes' => false ],
];
MediaWiki version:
1.27
$wgObjectCaches = [
	CACHE_NONE => [ 'class' => 'EmptyBagOStuff', 'reportDupes' => false ],
	CACHE_DB => [ 'class' => 'SqlBagOStuff', 'loggroup' => 'SQLBagOStuff' ],

	CACHE_ANYTHING => [ 'factory' => 'ObjectCache::newAnything' ],
	CACHE_ACCEL => [ 'factory' => 'ObjectCache::getLocalServerInstance' ],
	CACHE_MEMCACHED => [ 'class' => 'MemcachedPhpBagOStuff', 'loggroup' => 'memcached' ],

	'db-replicated' => [
		'class'       => 'ReplicatedBagOStuff',
		'readFactory' => [
			'class' => 'SqlBagOStuff',
			'args'  => [ [ 'slaveOnly' => true ] ]
		],
		'writeFactory' => [
			'class' => 'SqlBagOStuff',
			'args'  => [ [ 'slaveOnly' => false ] ]
		],
		'loggroup'  => 'SQLBagOStuff'
	],

	'apc' => [ 'class' => 'APCBagOStuff', 'reportDupes' => false ],
	'apcu' => [ 'class' => 'APCUBagOStuff', 'reportDupes' => false ],
	'xcache' => [ 'class' => 'XCacheBagOStuff', 'reportDupes' => false ],
	'wincache' => [ 'class' => 'WinCacheBagOStuff', 'reportDupes' => false ],
	'memcached-php' => [ 'class' => 'MemcachedPhpBagOStuff', 'loggroup' => 'memcached' ],
	'memcached-pecl' => [ 'class' => 'MemcachedPeclBagOStuff', 'loggroup' => 'memcached' ],
	'hash' => [ 'class' => 'HashBagOStuff', 'reportDupes' => false ],
];
MediaWiki version:
1.26
$wgObjectCaches = array(
	CACHE_NONE => array( 'class' => 'EmptyBagOStuff' ),
	CACHE_DB => array( 'class' => 'SqlBagOStuff', 'loggroup' => 'SQLBagOStuff' ),

	CACHE_ANYTHING => array( 'factory' => 'ObjectCache::newAnything' ),
	CACHE_ACCEL => array( 'factory' => 'ObjectCache::newAccelerator' ),
	CACHE_MEMCACHED => array( 'factory' => 'ObjectCache::newMemcached', 'loggroup' => 'memcached' ),

	'db-replicated' => array(
		'class'       => 'ReplicatedBagOStuff',
		'readFactory' => array(
			'class' => 'SqlBagOStuff',
			'args'  => array( array( 'slaveOnly' => true ) )
		),
		'writeFactory' => array(
			'class' => 'SqlBagOStuff',
			'args'  => array( array( 'slaveOnly' => false ) )
		),
		'loggroup'  => 'SQLBagOStuff'
	),

	'apc' => array( 'class' => 'APCBagOStuff' ),
	'xcache' => array( 'class' => 'XCacheBagOStuff' ),
	'wincache' => array( 'class' => 'WinCacheBagOStuff' ),
	'memcached-php' => array( 'class' => 'MemcachedPhpBagOStuff', 'loggroup' => 'memcached' ),
	'memcached-pecl' => array( 'class' => 'MemcachedPeclBagOStuff', 'loggroup' => 'memcached' ),
	'hash' => array( 'class' => 'HashBagOStuff' ),
);
MediaWiki versions:
1.23 – 1.25
$wgObjectCaches = array(
   CACHE_NONE => array( 'class' => 'EmptyBagOStuff' ),
   CACHE_DB => array( 'class' => 'SqlBagOStuff', 'table' => 'objectcache' ),
 
   CACHE_ANYTHING => array( 'factory' => 'ObjectCache::newAnything' ),
   CACHE_ACCEL => array( 'factory' => 'ObjectCache::newAccelerator' ),
   CACHE_MEMCACHED => array( 'factory' => 'ObjectCache::newMemcached' ),
 
   'apc' => array( 'class' => 'APCBagOStuff' ),
   'xcache' => array( 'class' => 'XCacheBagOStuff' ),
   'wincache' => array( 'class' => 'WinCacheBagOStuff' ),
   'memcached-php' => array( 'class' => 'MemcachedPhpBagOStuff' ),
   'memcached-pecl' => array( 'class' => 'MemcachedPeclBagOStuff' ),
   'hash' => array( 'class' => 'HashBagOStuff' ),
);
MediaWiki versions:
1.20 – 1.22
$wgObjectCaches = array(
   CACHE_NONE => array( 'class' => 'EmptyBagOStuff' ),
   CACHE_DB => array( 'class' => 'SqlBagOStuff', 'table' => 'objectcache' ),
   CACHE_DBA => array( 'class' => 'DBABagOStuff' ),
 
   CACHE_ANYTHING => array( 'factory' => 'ObjectCache::newAnything' ),
   CACHE_ACCEL => array( 'factory' => 'ObjectCache::newAccelerator' ),
   CACHE_MEMCACHED => array( 'factory' => 'ObjectCache::newMemcached' ),
 
   'apc' => array( 'class' => 'APCBagOStuff' ),
   'xcache' => array( 'class' => 'XCacheBagOStuff' ),
   'wincache' => array( 'class' => 'WinCacheBagOStuff' ),
   'memcached-php' => array( 'class' => 'MemcachedPhpBagOStuff' ),
   'memcached-pecl' => array( 'class' => 'MemcachedPeclBagOStuff' ),
   'hash' => array( 'class' => 'HashBagOStuff' ),
);
MediaWiki version:
1.19
$wgObjectCaches = array(
   CACHE_NONE => array( 'class' => 'EmptyBagOStuff' ),
   CACHE_DB => array( 'class' => 'SqlBagOStuff', 'table' => 'objectcache' ),
   CACHE_DBA => array( 'class' => 'DBABagOStuff' ),
 
   CACHE_ANYTHING => array( 'factory' => 'ObjectCache::newAnything' ),
   CACHE_ACCEL => array( 'factory' => 'ObjectCache::newAccelerator' ),
   CACHE_MEMCACHED => array( 'factory' => 'ObjectCache::newMemcached' ),
 
   'apc' => array( 'class' => 'APCBagOStuff' ),
   'xcache' => array( 'class' => 'XCacheBagOStuff' ),
   'wincache' => array( 'class' => 'WinCacheBagOStuff' ),
   'memcached-php' => array( 'class' => 'MemcachedPhpBagOStuff' ),
   'hash' => array( 'class' => 'HashBagOStuff' ),
);
MediaWiki version:
1.18
$wgObjectCaches = array(
   CACHE_NONE => array( 'class' => 'EmptyBagOStuff' ),
   CACHE_DB => array( 'class' => 'SqlBagOStuff', 'table' => 'objectcache' ),
   CACHE_DBA => array( 'class' => 'DBABagOStuff' ),

   CACHE_ANYTHING => array( 'factory' => 'ObjectCache::newAnything' ),
   CACHE_ACCEL => array( 'factory' => 'ObjectCache::newAccelerator' ),
   CACHE_MEMCACHED => array( 'factory' => 'ObjectCache::newMemcached' ),

   'eaccelerator' => array( 'class' => 'eAccelBagOStuff' ),
   'apc' => array( 'class' => 'APCBagOStuff' ),
   'xcache' => array( 'class' => 'XCacheBagOStuff' ),
   'wincache' => array( 'class' => 'WinCacheBagOStuff' ),
   'memcached-php' => array( 'class' => 'MemcachedPhpBagOStuff' ),
   'hash' => array( 'class' => 'HashBagOStuff' ),
);