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:
|
|
|
|
|
*
|
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::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.
|
|
|
|
|
*
|
2019-10-08 21:37:04 +00:00
|
|
|
* All the above BagOStuff cache instances have their makeKey()
|
2015-10-17 22:12:20 +00:00
|
|
|
* 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 = [];
|
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
|
|
|
|
* 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
|
|
|
*/
|
2019-08-13 00:46:14 +00:00
|
|
|
private 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
|
|
|
|
|
*/
|
2019-08-13 00:46:14 +00:00
|
|
|
private 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;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 20:28:45 +00:00
|
|
|
return WikiMap::getCurrentWikiDbDomain()->getId();
|
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 ) {
|
2019-10-10 20:30:47 +00:00
|
|
|
$params['logger'] = $params['logger'] ??
|
|
|
|
|
LoggerFactory::getInstance( $params['loggroup'] ?? 'objectcache' );
|
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
|
2019-08-08 16:38:55 +00:00
|
|
|
$params['asyncHandler'] = $params['asyncHandler']
|
|
|
|
|
?? [ DeferredUpdates::class, 'addCallableUpdate' ];
|
2016-03-02 02:25:55 +00:00
|
|
|
// Enable reportDupes by default
|
2017-10-06 22:17:58 +00:00
|
|
|
$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['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 ) {
|
|
|
|
|
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 ) ) {
|
2017-10-06 22:17:58 +00:00
|
|
|
$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-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-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 = [];
|
2015-08-24 21:21:56 +00:00
|
|
|
}
|
2018-05-01 00:35:08 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detects which local server cache library is present and returns a configuration for it
|
|
|
|
|
* @since 1.32
|
|
|
|
|
*
|
|
|
|
|
* @return int|string Index to cache in $wgObjectCaches
|
|
|
|
|
*/
|
|
|
|
|
public static function detectLocalServerCache() {
|
2019-05-22 16:30:50 +00:00
|
|
|
if ( function_exists( 'apcu_fetch' ) ) {
|
2019-08-28 14:23:19 +00:00
|
|
|
// Make sure the APCu methods actually store anything
|
|
|
|
|
if ( PHP_SAPI !== 'cli' || ini_get( 'apc.enable_cli' ) ) {
|
|
|
|
|
return 'apcu';
|
|
|
|
|
}
|
2019-05-22 16:30:50 +00:00
|
|
|
} elseif ( function_exists( 'apc_fetch' ) ) {
|
2019-08-28 14:23:19 +00:00
|
|
|
// Make sure the APC methods actually store anything
|
|
|
|
|
if ( PHP_SAPI !== 'cli' || ini_get( 'apc.enable_cli' ) ) {
|
|
|
|
|
return 'apc';
|
|
|
|
|
}
|
2018-05-01 00:35:08 +00:00
|
|
|
} elseif ( function_exists( 'wincache_ucache_get' ) ) {
|
|
|
|
|
return 'wincache';
|
|
|
|
|
}
|
2019-08-28 14:23:19 +00:00
|
|
|
|
2018-05-01 00:35:08 +00:00
|
|
|
return CACHE_NONE;
|
|
|
|
|
}
|
2005-04-09 10:30:45 +00:00
|
|
|
}
|