2004-05-09 05:12:55 +00:00
|
|
|
<?php
|
2005-04-12 01:29:21 +00:00
|
|
|
/**
|
2012-05-02 08:51:15 +00:00
|
|
|
* Functions to get cache objects.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-14 17:52:00 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup Cache
|
2005-04-12 01:29:21 +00:00
|
|
|
*/
|
2012-05-02 08:51:15 +00:00
|
|
|
|
2015-03-23 00:53:24 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2016-04-23 00:09:14 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2015-03-23 00:53:24 +00:00
|
|
|
|
2012-05-02 08:51:15 +00:00
|
|
|
/**
|
|
|
|
|
* Functions to get cache objects
|
|
|
|
|
*
|
2015-04-30 02:19:23 +00:00
|
|
|
* The word "cache" has two main dictionary meanings, and both
|
|
|
|
|
* are used in this factory class. They are:
|
2015-08-24 21:21:56 +00:00
|
|
|
*
|
|
|
|
|
* - a) Cache (the computer science definition).
|
|
|
|
|
* A place to store copies or computations on existing data for
|
|
|
|
|
* higher access speeds.
|
|
|
|
|
* - b) Storage.
|
|
|
|
|
* A place to store lightweight data that is not canonically
|
|
|
|
|
* stored anywhere else (e.g. a "hoard" of objects).
|
2015-05-27 18:52:44 +00:00
|
|
|
*
|
|
|
|
|
* The former should always use strongly consistent stores, so callers don't
|
2016-09-07 19:43:57 +00:00
|
|
|
* have to deal with stale reads. The latter may be eventually consistent, but
|
2015-05-27 18:52:44 +00:00
|
|
|
* callers can use BagOStuff:READ_LATEST to see the latest available data.
|
2015-04-30 02:19:23 +00:00
|
|
|
*
|
2015-08-24 21:21:56 +00:00
|
|
|
* Primary entry points:
|
|
|
|
|
*
|
|
|
|
|
* - ObjectCache::getMainWANInstance()
|
2015-10-31 18:42:48 +00:00
|
|
|
* Purpose: Memory cache.
|
2015-12-07 19:52:42 +00:00
|
|
|
* Stored in the local data-center's main cache (keyspace different from local-cluster cache).
|
|
|
|
|
* Delete events are broadcasted to other DCs main cache. See WANObjectCache for details.
|
2015-08-24 21:21:56 +00:00
|
|
|
*
|
2015-10-31 18:42:48 +00:00
|
|
|
* - ObjectCache::getLocalServerInstance( $fallbackType )
|
|
|
|
|
* Purpose: Memory cache for very hot keys.
|
2016-10-01 17:00:53 +00:00
|
|
|
* Stored only on the individual web server (typically APC or APCu for web requests,
|
2015-12-07 19:52:42 +00:00
|
|
|
* and EmptyBagOStuff in CLI mode).
|
2015-10-31 18:42:48 +00:00
|
|
|
* Not replicated to the other servers.
|
2015-08-24 21:21:56 +00:00
|
|
|
*
|
2015-10-19 17:56:41 +00:00
|
|
|
* - ObjectCache::getLocalClusterInstance()
|
|
|
|
|
* Purpose: Memory storage for per-cluster coordination and tracking.
|
|
|
|
|
* A typical use case would be a rate limit counter or cache regeneration mutex.
|
|
|
|
|
* Stored centrally within the local data-center. Not replicated to other DCs.
|
2015-10-31 20:05:03 +00:00
|
|
|
* Configured by $wgMainCacheType.
|
2015-10-19 17:56:41 +00:00
|
|
|
*
|
2015-10-31 18:42:48 +00:00
|
|
|
* - ObjectCache::getMainStashInstance()
|
|
|
|
|
* Purpose: Ephemeral global storage.
|
|
|
|
|
* Stored centrally within the primary data-center.
|
|
|
|
|
* Changes are applied there first and replicated to other DCs (best-effort).
|
2016-09-05 20:21:26 +00:00
|
|
|
* To retrieve the latest value (e.g. not from a replica DB), use BagOStuff::READ_LATEST.
|
2015-10-31 18:42:48 +00:00
|
|
|
* This store may be subject to LRU style evictions.
|
|
|
|
|
*
|
|
|
|
|
* - ObjectCache::getInstance( $cacheType )
|
|
|
|
|
* Purpose: Special cases (like tiered memory/disk caches).
|
2015-08-24 21:21:56 +00:00
|
|
|
* Get a specific cache type by key in $wgObjectCaches.
|
|
|
|
|
*
|
2015-10-17 22:12:20 +00:00
|
|
|
* All the above cache instances (BagOStuff and WANObjectCache) have their makeKey()
|
|
|
|
|
* method scoped to the *current* wiki ID. Use makeGlobalKey() to avoid this scoping
|
|
|
|
|
* when using keys that need to be shared amongst wikis.
|
|
|
|
|
*
|
2012-05-02 08:51:15 +00:00
|
|
|
* @ingroup Cache
|
|
|
|
|
*/
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
class ObjectCache {
|
2015-10-10 07:18:00 +00:00
|
|
|
/** @var BagOStuff[] Map of (id => BagOStuff) */
|
2016-02-17 09:09:32 +00:00
|
|
|
public static $instances = [];
|
2015-10-10 07:18:00 +00:00
|
|
|
/** @var WANObjectCache[] Map of (id => WANObjectCache) */
|
2016-02-17 09:09:32 +00:00
|
|
|
public static $wanInstances = [];
|
2004-08-21 13:59:48 +00:00
|
|
|
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
/**
|
|
|
|
|
* Get a cached instance of the specified type of cache object.
|
2011-05-28 17:18:50 +00:00
|
|
|
*
|
2015-08-24 21:21:56 +00:00
|
|
|
* @param string $id A key in $wgObjectCaches.
|
2013-06-28 21:48:31 +00:00
|
|
|
* @return BagOStuff
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
*/
|
2015-08-24 21:21:56 +00:00
|
|
|
public static function getInstance( $id ) {
|
2015-06-10 03:53:41 +00:00
|
|
|
if ( !isset( self::$instances[$id] ) ) {
|
|
|
|
|
self::$instances[$id] = self::newFromId( $id );
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
}
|
2004-09-02 23:28:24 +00:00
|
|
|
|
2015-06-10 03:53:41 +00:00
|
|
|
return self::$instances[$id];
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
}
|
2004-08-27 13:40:27 +00:00
|
|
|
|
2015-01-27 19:56:44 +00:00
|
|
|
/**
|
2015-08-24 21:21:56 +00:00
|
|
|
* Get a cached instance of the specified type of WAN cache object.
|
2015-01-27 19:56:44 +00:00
|
|
|
*
|
2015-06-10 03:53:41 +00:00
|
|
|
* @since 1.26
|
2015-08-24 21:21:56 +00:00
|
|
|
* @param string $id A key in $wgWANObjectCaches.
|
2015-01-27 19:56:44 +00:00
|
|
|
* @return WANObjectCache
|
|
|
|
|
*/
|
2015-08-24 21:21:56 +00:00
|
|
|
public static function getWANInstance( $id ) {
|
2015-06-10 03:53:41 +00:00
|
|
|
if ( !isset( self::$wanInstances[$id] ) ) {
|
|
|
|
|
self::$wanInstances[$id] = self::newWANCacheFromId( $id );
|
2015-01-27 19:56:44 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-10 03:53:41 +00:00
|
|
|
return self::$wanInstances[$id];
|
2015-01-27 19:56:44 +00:00
|
|
|
}
|
|
|
|
|
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
/**
|
|
|
|
|
* Create a new cache object of the specified type.
|
2011-05-29 14:25:20 +00:00
|
|
|
*
|
2015-08-24 21:21:56 +00:00
|
|
|
* @param string $id A key in $wgObjectCaches.
|
2013-06-28 21:48:31 +00:00
|
|
|
* @return BagOStuff
|
2016-09-21 16:38:34 +00:00
|
|
|
* @throws InvalidArgumentException
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
*/
|
2015-08-24 21:21:56 +00:00
|
|
|
public static function newFromId( $id ) {
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
global $wgObjectCaches;
|
|
|
|
|
|
|
|
|
|
if ( !isset( $wgObjectCaches[$id] ) ) {
|
2016-09-21 16:38:34 +00:00
|
|
|
// Always recognize these ones
|
|
|
|
|
if ( $id === CACHE_NONE ) {
|
|
|
|
|
return new EmptyBagOStuff();
|
|
|
|
|
} elseif ( $id === 'hash' ) {
|
|
|
|
|
return new HashBagOStuff();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new InvalidArgumentException( "Invalid object cache type \"$id\" requested. " .
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
"It is not present in \$wgObjectCaches." );
|
2004-05-09 05:12:55 +00:00
|
|
|
}
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
|
|
|
|
|
return self::newFromParams( $wgObjectCaches[$id] );
|
2006-06-01 08:19:02 +00:00
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2015-10-09 23:35:08 +00:00
|
|
|
/**
|
|
|
|
|
* Get the default keyspace for this wiki.
|
|
|
|
|
*
|
|
|
|
|
* This is either the value of the `CachePrefix` configuration variable,
|
|
|
|
|
* or (if the former is unset) the `DBname` configuration variable, with
|
|
|
|
|
* `DBprefix` (if defined).
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function getDefaultKeyspace() {
|
2015-10-27 23:43:40 +00:00
|
|
|
global $wgCachePrefix;
|
2015-10-09 23:35:08 +00:00
|
|
|
|
|
|
|
|
$keyspace = $wgCachePrefix;
|
|
|
|
|
if ( is_string( $keyspace ) && $keyspace !== '' ) {
|
|
|
|
|
return $keyspace;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-27 23:43:40 +00:00
|
|
|
return wfWikiID();
|
2015-10-09 23:35:08 +00:00
|
|
|
}
|
|
|
|
|
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
/**
|
2015-08-24 21:21:56 +00:00
|
|
|
* Create a new cache object from parameters.
|
2011-05-28 17:18:50 +00:00
|
|
|
*
|
2015-08-24 21:21:56 +00:00
|
|
|
* @param array $params Must have 'factory' or 'class' property.
|
|
|
|
|
* - factory: Callback passed $params that returns BagOStuff.
|
|
|
|
|
* - class: BagOStuff subclass constructed with $params.
|
|
|
|
|
* - loggroup: Alias to set 'logger' key with LoggerFactory group.
|
|
|
|
|
* - .. Other parameters passed to factory or class.
|
2013-06-28 21:48:31 +00:00
|
|
|
* @return BagOStuff
|
2016-09-21 16:38:34 +00:00
|
|
|
* @throws InvalidArgumentException
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
*/
|
2015-08-24 21:21:56 +00:00
|
|
|
public static function newFromParams( $params ) {
|
2014-11-19 06:42:33 +00:00
|
|
|
if ( isset( $params['loggroup'] ) ) {
|
2015-03-23 00:53:24 +00:00
|
|
|
$params['logger'] = LoggerFactory::getInstance( $params['loggroup'] );
|
2014-11-19 06:42:33 +00:00
|
|
|
} else {
|
2015-03-23 00:53:24 +00:00
|
|
|
$params['logger'] = LoggerFactory::getInstance( 'objectcache' );
|
2014-11-19 06:42:33 +00:00
|
|
|
}
|
2015-10-09 23:35:08 +00:00
|
|
|
if ( !isset( $params['keyspace'] ) ) {
|
|
|
|
|
$params['keyspace'] = self::getDefaultKeyspace();
|
|
|
|
|
}
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
if ( isset( $params['factory'] ) ) {
|
|
|
|
|
return call_user_func( $params['factory'], $params );
|
|
|
|
|
} elseif ( isset( $params['class'] ) ) {
|
|
|
|
|
$class = $params['class'];
|
2015-10-24 21:47:19 +00:00
|
|
|
// Automatically set the 'async' update handler
|
2016-03-02 02:25:55 +00:00
|
|
|
$params['asyncHandler'] = isset( $params['asyncHandler'] )
|
|
|
|
|
? $params['asyncHandler']
|
|
|
|
|
: 'DeferredUpdates::addCallableUpdate';
|
|
|
|
|
// Enable reportDupes by default
|
|
|
|
|
$params['reportDupes'] = isset( $params['reportDupes'] )
|
|
|
|
|
? $params['reportDupes']
|
|
|
|
|
: true;
|
2016-09-19 19:01:56 +00:00
|
|
|
// Do b/c logic for SqlBagOStuff
|
2016-10-05 09:46:50 +00:00
|
|
|
if ( is_a( $class, SqlBagOStuff::class, true ) ) {
|
2016-09-19 19:01:56 +00:00
|
|
|
if ( isset( $params['server'] ) && !isset( $params['servers'] ) ) {
|
|
|
|
|
$params['servers'] = [ $params['server'] ];
|
2016-09-21 16:38:34 +00:00
|
|
|
unset( $params['server'] );
|
2016-09-19 19:01:56 +00:00
|
|
|
}
|
|
|
|
|
// In the past it was not required to set 'dbDirectory' in $wgObjectCaches
|
|
|
|
|
if ( isset( $params['servers'] ) ) {
|
|
|
|
|
foreach ( $params['servers'] as &$server ) {
|
|
|
|
|
if ( $server['type'] === 'sqlite' && !isset( $server['dbDirectory'] ) ) {
|
|
|
|
|
$server['dbDirectory'] = MediaWikiServices::getInstance()
|
|
|
|
|
->getMainConfig()->get( 'SQLiteDataDir' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-24 21:47:19 +00:00
|
|
|
// Do b/c logic for MemcachedBagOStuff
|
2016-09-19 19:01:56 +00:00
|
|
|
if ( is_subclass_of( $class, MemcachedBagOStuff::class ) ) {
|
2015-10-24 21:47:19 +00:00
|
|
|
if ( !isset( $params['servers'] ) ) {
|
|
|
|
|
$params['servers'] = $GLOBALS['wgMemCachedServers'];
|
|
|
|
|
}
|
|
|
|
|
if ( !isset( $params['debug'] ) ) {
|
|
|
|
|
$params['debug'] = $GLOBALS['wgMemCachedDebug'];
|
|
|
|
|
}
|
|
|
|
|
if ( !isset( $params['persistent'] ) ) {
|
|
|
|
|
$params['persistent'] = $GLOBALS['wgMemCachedPersistent'];
|
|
|
|
|
}
|
|
|
|
|
if ( !isset( $params['timeout'] ) ) {
|
|
|
|
|
$params['timeout'] = $GLOBALS['wgMemCachedTimeout'];
|
|
|
|
|
}
|
2015-10-09 08:01:28 +00:00
|
|
|
}
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
return new $class( $params );
|
|
|
|
|
} else {
|
2016-09-21 16:38:34 +00:00
|
|
|
throw new InvalidArgumentException( "The definition of cache type \""
|
2014-05-11 09:08:36 +00:00
|
|
|
. print_r( $params, true ) . "\" lacks both "
|
|
|
|
|
. "factory and class parameters." );
|
2006-06-01 08:19:02 +00:00
|
|
|
}
|
2004-08-21 13:59:48 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
/**
|
2015-08-24 21:21:56 +00:00
|
|
|
* Factory function for CACHE_ANYTHING (referenced from DefaultSettings.php)
|
2012-03-04 22:53:05 +00:00
|
|
|
*
|
|
|
|
|
* CACHE_ANYTHING means that stuff has to be cached, not caching is not an option.
|
|
|
|
|
* If a caching method is configured for any of the main caches ($wgMainCacheType,
|
|
|
|
|
* $wgMessageCacheType, $wgParserCacheType), then CACHE_ANYTHING will effectively
|
2012-03-08 03:19:51 +00:00
|
|
|
* be an alias to the configured cache choice for that.
|
|
|
|
|
* If no cache choice is configured (by default $wgMainCacheType is CACHE_NONE),
|
2012-03-04 22:53:05 +00:00
|
|
|
* then CACHE_ANYTHING will forward to CACHE_DB.
|
2015-06-10 03:53:41 +00:00
|
|
|
*
|
2014-04-18 23:19:46 +00:00
|
|
|
* @param array $params
|
2013-06-28 21:48:31 +00:00
|
|
|
* @return BagOStuff
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
*/
|
2015-08-24 21:21:56 +00:00
|
|
|
public static function newAnything( $params ) {
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
|
2016-02-17 09:09:32 +00:00
|
|
|
$candidates = [ $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType ];
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
foreach ( $candidates as $candidate ) {
|
2017-03-15 22:51:13 +00:00
|
|
|
$cache = false;
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
if ( $candidate !== CACHE_NONE && $candidate !== CACHE_ANYTHING ) {
|
2017-03-15 22:51:13 +00:00
|
|
|
$cache = self::getInstance( $candidate );
|
|
|
|
|
// CACHE_ACCEL might default to nothing if no APCu
|
|
|
|
|
// See includes/ServiceWiring.php
|
|
|
|
|
if ( !( $cache instanceof EmptyBagOStuff ) ) {
|
|
|
|
|
return $cache;
|
|
|
|
|
}
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
}
|
2006-06-01 08:19:02 +00:00
|
|
|
}
|
2016-05-13 19:27:06 +00:00
|
|
|
|
2016-08-02 10:57:52 +00:00
|
|
|
if ( MediaWikiServices::getInstance()->isServiceDisabled( 'DBLoadBalancer' ) ) {
|
2016-05-13 19:27:06 +00:00
|
|
|
// The LoadBalancer is disabled, probably because
|
|
|
|
|
// MediaWikiServices::disableStorageBackend was called.
|
|
|
|
|
$candidate = CACHE_NONE;
|
2016-08-02 10:57:52 +00:00
|
|
|
} else {
|
|
|
|
|
$candidate = CACHE_DB;
|
2016-05-13 19:27:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self::getInstance( $candidate );
|
2006-06-01 07:22:49 +00:00
|
|
|
}
|
2006-06-01 08:19:02 +00:00
|
|
|
|
* Rewrote ObjectCache.php to conform to the modern coding style, and to be less convoluted about how CACHE_ANYTHING and CACHE_ACCEL are resolved. Moved most functionality to static members of a new ObjectCache class.
* Moved the global functions to GlobalFunctions.php, where they are now just convenience wrappers. Made them return non-references. Updated callers (none found in extensions).
* Added an advanced configuration method, $wgObjectCaches, which allows a lot more detail in the object cache configuration than $wgMainCacheType.
* Made all object cache classes derive from BagOStuff.
* Split the MWMemcached class into a generic client class and a MediaWiki-specific wrapper class. The wrapper class presents a simple BagOStuff interface to calling code, hiding memcached client internals, and will simplify the task of supporting the PECL extension.
* Added some extra constructor parameters to MWMemcached, configurable via $wgObjectCaches.
* Removed the *_multi() methods from BagOStuff, my grepping indicates that they are not used.
* Rewrote FakeMemCachedClient as a BagOStuff subclass, called EmptyBagOStuff.
* Added an optional "server" parameter to SQLBagOStuff. This allows the server holding the objectcache table to be different from the server holding the core DB.
* Added MultiWriteBagOStuff: a cache class which writes to multiple locations, and reads from them in a defined fallback sequence. This can be used to extend the cache space by adding disk-backed storage to existing in-memory caches.
* Made MWMemcached::get() return false on failure instead of null, to match the BagOStuff documentation and the other BagOStuff subclasses. Anything that was relying on it returning null would have already been broken with SqlBagOStuff.
* Fixed a bug in the memcached client causing keys with spaces or line breaks in them to break the memcached protocol, injecting arbitrary commands or parameters. Since the PECL client apparently also has this flaw, I implemented the fix in the wrapper class.
* Renamed BagOStuff::set_debug() to setDebug(), since we aren't emulating the memcached client anymore
* Fixed spelling error in MWMemcached: persistant -> persistent
2011-03-03 09:37:37 +00:00
|
|
|
/**
|
2015-08-24 21:21:56 +00:00
|
|
|
* Factory function for CACHE_ACCEL (referenced from DefaultSettings.php)
|
2011-05-28 18:59:42 +00:00
|
|
|
*
|
2016-10-01 17:00:53 +00:00
|
|
|
* This will look for any APC or APCu style server-local cache.
|
2014-07-10 17:46:42 +00:00
|
|
|
* A fallback cache can be specified if none is found.
|
|
|
|
|
*
|
2015-10-02 19:01:38 +00:00
|
|
|
* // Direct calls
|
2015-10-31 18:42:48 +00:00
|
|
|
* ObjectCache::getLocalServerInstance( $fallbackType );
|
2015-10-02 19:01:38 +00:00
|
|
|
*
|
|
|
|
|
* // From $wgObjectCaches via newFromParams()
|
2016-08-13 01:10:40 +00:00
|
|
|
* ObjectCache::getLocalServerInstance( [ 'fallback' => $fallbackType ] );
|
2015-10-02 19:01:38 +00:00
|
|
|
*
|
2016-09-29 08:43:58 +00:00
|
|
|
* @param int|string|array $fallback Fallback cache or parameter map with 'fallback'
|
2015-10-31 18:42:48 +00:00
|
|
|
* @return BagOStuff
|
2016-09-21 16:38:34 +00:00
|
|
|
* @throws InvalidArgumentException
|
2015-10-31 18:42:48 +00:00
|
|
|
* @since 1.27
|
|
|
|
|
*/
|
|
|
|
|
public static function getLocalServerInstance( $fallback = CACHE_NONE ) {
|
2016-09-29 19:36:27 +00:00
|
|
|
$cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
|
|
|
|
|
if ( $cache instanceof EmptyBagOStuff ) {
|
2016-09-29 08:43:58 +00:00
|
|
|
if ( is_array( $fallback ) ) {
|
2016-09-29 19:36:27 +00:00
|
|
|
$fallback = isset( $fallback['fallback'] ) ? $fallback['fallback'] : CACHE_NONE;
|
2016-09-29 08:43:58 +00:00
|
|
|
}
|
2016-09-29 19:36:27 +00:00
|
|
|
$cache = self::getInstance( $fallback );
|
2016-09-29 08:43:58 +00:00
|
|
|
}
|
2015-10-31 18:42:48 +00:00
|
|
|
|
2016-09-29 19:36:27 +00:00
|
|
|
return $cache;
|
2015-10-31 18:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-27 19:56:44 +00:00
|
|
|
/**
|
2015-08-24 21:21:56 +00:00
|
|
|
* Create a new cache object of the specified type.
|
2015-01-27 19:56:44 +00:00
|
|
|
*
|
2015-06-10 03:53:41 +00:00
|
|
|
* @since 1.26
|
2015-08-24 21:21:56 +00:00
|
|
|
* @param string $id A key in $wgWANObjectCaches.
|
2015-01-27 19:56:44 +00:00
|
|
|
* @return WANObjectCache
|
2016-09-21 16:47:34 +00:00
|
|
|
* @throws UnexpectedValueException
|
2015-01-27 19:56:44 +00:00
|
|
|
*/
|
2015-08-24 21:21:56 +00:00
|
|
|
public static function newWANCacheFromId( $id ) {
|
2016-09-21 16:47:34 +00:00
|
|
|
global $wgWANObjectCaches, $wgObjectCaches;
|
2015-01-27 19:56:44 +00:00
|
|
|
|
|
|
|
|
if ( !isset( $wgWANObjectCaches[$id] ) ) {
|
2016-09-21 16:47:34 +00:00
|
|
|
throw new UnexpectedValueException(
|
|
|
|
|
"Cache type \"$id\" requested is not present in \$wgWANObjectCaches." );
|
2015-01-27 19:56:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$params = $wgWANObjectCaches[$id];
|
2016-09-21 16:47:34 +00:00
|
|
|
if ( !isset( $wgObjectCaches[$params['cacheId']] ) ) {
|
|
|
|
|
throw new UnexpectedValueException(
|
|
|
|
|
"Cache type \"{$params['cacheId']}\" is not present in \$wgObjectCaches." );
|
|
|
|
|
}
|
|
|
|
|
$params['store'] = $wgObjectCaches[$params['cacheId']];
|
|
|
|
|
|
|
|
|
|
return self::newWANCacheFromParams( $params );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new cache object of the specified type.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.28
|
|
|
|
|
* @param array $params
|
|
|
|
|
* @return WANObjectCache
|
|
|
|
|
* @throws UnexpectedValueException
|
|
|
|
|
*/
|
|
|
|
|
public static function newWANCacheFromParams( array $params ) {
|
2017-11-18 20:18:01 +00:00
|
|
|
global $wgCommandLineMode;
|
|
|
|
|
|
2017-10-19 02:50:17 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
|
|
|
|
|
$erGroup = $services->getEventRelayerGroup();
|
2016-04-22 19:52:06 +00:00
|
|
|
foreach ( $params['channels'] as $action => $channel ) {
|
2016-10-24 04:01:03 +00:00
|
|
|
$params['relayers'][$action] = $erGroup->getRelayer( $channel );
|
2016-04-22 19:52:06 +00:00
|
|
|
$params['channels'][$action] = $channel;
|
|
|
|
|
}
|
2016-09-21 16:47:34 +00:00
|
|
|
$params['cache'] = self::newFromParams( $params['store'] );
|
2015-10-21 05:55:51 +00:00
|
|
|
if ( isset( $params['loggroup'] ) ) {
|
|
|
|
|
$params['logger'] = LoggerFactory::getInstance( $params['loggroup'] );
|
|
|
|
|
} else {
|
|
|
|
|
$params['logger'] = LoggerFactory::getInstance( 'objectcache' );
|
|
|
|
|
}
|
2017-11-18 20:18:01 +00:00
|
|
|
if ( !$wgCommandLineMode ) {
|
2017-12-02 20:34:22 +00:00
|
|
|
// Send the statsd data post-send on HTTP requests; avoid in CLI mode (T181385)
|
|
|
|
|
$params['stats'] = $services->getStatsdDataFactory();
|
|
|
|
|
// Let pre-emptive refreshes happen post-send on HTTP requests
|
2017-11-18 20:18:01 +00:00
|
|
|
$params['asyncHandler'] = [ DeferredUpdates::class, 'addCallableUpdate' ];
|
|
|
|
|
}
|
2015-01-27 19:56:44 +00:00
|
|
|
$class = $params['class'];
|
|
|
|
|
|
|
|
|
|
return new $class( $params );
|
|
|
|
|
}
|
2015-04-27 21:23:32 +00:00
|
|
|
|
2015-10-09 23:26:26 +00:00
|
|
|
/**
|
|
|
|
|
* Get the main cluster-local cache object.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.27
|
|
|
|
|
* @return BagOStuff
|
|
|
|
|
*/
|
2015-10-19 17:56:41 +00:00
|
|
|
public static function getLocalClusterInstance() {
|
2015-10-09 23:35:08 +00:00
|
|
|
global $wgMainCacheType;
|
|
|
|
|
|
|
|
|
|
return self::getInstance( $wgMainCacheType );
|
2015-10-09 23:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-27 21:23:32 +00:00
|
|
|
/**
|
2015-08-24 21:21:56 +00:00
|
|
|
* Get the main WAN cache object.
|
2015-04-27 21:23:32 +00:00
|
|
|
*
|
|
|
|
|
* @since 1.26
|
2015-06-10 03:53:41 +00:00
|
|
|
* @return WANObjectCache
|
2017-03-10 09:42:43 +00:00
|
|
|
* @deprecated Since 1.28 Use MediaWikiServices::getMainWANObjectCache()
|
2015-04-27 21:23:32 +00:00
|
|
|
*/
|
2015-08-24 21:21:56 +00:00
|
|
|
public static function getMainWANInstance() {
|
2016-09-29 19:36:27 +00:00
|
|
|
return MediaWikiServices::getInstance()->getMainWANObjectCache();
|
2015-04-27 21:23:32 +00:00
|
|
|
}
|
2015-04-30 02:19:23 +00:00
|
|
|
|
|
|
|
|
/**
|
2015-08-24 21:21:56 +00:00
|
|
|
* Get the cache object for the main stash.
|
|
|
|
|
*
|
2015-04-30 02:19:23 +00:00
|
|
|
* Stash objects are BagOStuff instances suitable for storing light
|
|
|
|
|
* weight data that is not canonically stored elsewhere (such as RDBMS).
|
|
|
|
|
* Stashes should be configured to propagate changes to all data-centers.
|
|
|
|
|
*
|
|
|
|
|
* Callers should be prepared for:
|
|
|
|
|
* - a) Writes to be slower in non-"primary" (e.g. HTTP GET/HEAD only) DCs
|
|
|
|
|
* - b) Reads to be eventually consistent, e.g. for get()/getMulti()
|
|
|
|
|
* In general, this means avoiding updates on idempotent HTTP requests and
|
|
|
|
|
* avoiding an assumption of perfect serializability (or accepting anomalies).
|
|
|
|
|
* Reads may be eventually consistent or data might rollback as nodes flap.
|
2015-05-27 18:52:44 +00:00
|
|
|
* Callers can use BagOStuff:READ_LATEST to see the latest available data.
|
2015-04-30 02:19:23 +00:00
|
|
|
*
|
2015-06-10 03:53:41 +00:00
|
|
|
* @return BagOStuff
|
2015-05-27 18:52:44 +00:00
|
|
|
* @since 1.26
|
2016-09-29 19:36:27 +00:00
|
|
|
* @deprecated Since 1.28 Use MediaWikiServices::getMainObjectStash
|
2015-04-30 02:19:23 +00:00
|
|
|
*/
|
2015-08-24 21:21:56 +00:00
|
|
|
public static function getMainStashInstance() {
|
2016-09-29 19:36:27 +00:00
|
|
|
return MediaWikiServices::getInstance()->getMainObjectStash();
|
2015-04-30 02:19:23 +00:00
|
|
|
}
|
2015-08-24 21:21:56 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clear all the cached instances.
|
|
|
|
|
*/
|
|
|
|
|
public static function clear() {
|
2016-02-17 09:09:32 +00:00
|
|
|
self::$instances = [];
|
|
|
|
|
self::$wanInstances = [];
|
2015-08-24 21:21:56 +00:00
|
|
|
}
|
2005-04-09 10:30:45 +00:00
|
|
|
}
|