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
|
|
|
|
2016-04-23 00:09:14 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2024-07-09 13:37:44 +00:00
|
|
|
use Wikimedia\ObjectCache\BagOStuff;
|
2015-03-23 00:53:24 +00:00
|
|
|
|
2012-05-02 08:51:15 +00:00
|
|
|
/**
|
2024-04-16 09:19:34 +00:00
|
|
|
* @see ObjectCacheFactory
|
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 {
|
2023-09-07 15:12:17 +00:00
|
|
|
/**
|
2024-04-30 17:24:34 +00:00
|
|
|
* @deprecated since 1.43; use ObjectCacheFactory instead.
|
2023-09-07 15:12:17 +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
|
|
|
*
|
2024-04-30 17:24:34 +00:00
|
|
|
* @deprecated since 1.43; use ObjectCacheFactory::getInstance instead.
|
2011-05-29 14:25:20 +00:00
|
|
|
*
|
2019-12-29 19:03:05 +00:00
|
|
|
* @param string|int $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
|
|
|
*/
|
2023-09-07 15:12:17 +00:00
|
|
|
public static function getInstance( $id ) {
|
|
|
|
|
return MediaWikiServices::getInstance()->getObjectCacheFactory()->getInstance( $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
|
|
|
/**
|
2023-09-07 15:12:17 +00:00
|
|
|
* @see ObjectCacheFactory::newFromParams()
|
2015-10-09 23:35:08 +00:00
|
|
|
*
|
2023-09-07 15:12:17 +00:00
|
|
|
* @deprecated since 1.42, Use ObjectCacheFactory::newFromParams instead.
|
|
|
|
|
* @param array $params
|
2011-05-28 17:18:50 +00:00
|
|
|
*
|
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
|
|
|
*/
|
2023-09-07 15:12:17 +00:00
|
|
|
public static function newFromParams( array $params ) {
|
|
|
|
|
return MediaWikiServices::getInstance()->getObjectCacheFactory()
|
|
|
|
|
->newFromParams( $params );
|
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
|
|
|
/**
|
2022-02-21 15:41:07 +00:00
|
|
|
* Factory function for CACHE_ANYTHING (referenced by configuration)
|
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
|
|
|
*
|
2024-05-13 11:16:27 +00:00
|
|
|
* @deprecated since 1.42, Use ObjectCacheFactory::getInstance( CACHE_ANYTHING );
|
2023-09-07 15:12:17 +00:00
|
|
|
*
|
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
|
|
|
*/
|
2023-09-07 15:12:17 +00:00
|
|
|
public static function newAnything() {
|
|
|
|
|
return MediaWikiServices::getInstance()->getObjectCacheFactory()
|
2024-05-13 11:16:27 +00:00
|
|
|
->getInstance( CACHE_ANYTHING );
|
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
|
|
|
/**
|
2024-03-27 19:11:49 +00:00
|
|
|
* @deprecated since 1.42, Use ObjectCacheFactory::getLocalServerInstance()
|
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
|
|
|
|
|
* @since 1.27
|
|
|
|
|
*/
|
|
|
|
|
public static function getLocalServerInstance( $fallback = CACHE_NONE ) {
|
2023-09-07 15:12:17 +00:00
|
|
|
return MediaWikiServices::getInstance()->getObjectCacheFactory()
|
|
|
|
|
->getLocalServerInstance( $fallback );
|
2015-10-31 18:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-09 23:26:26 +00:00
|
|
|
/**
|
|
|
|
|
* Get the main cluster-local cache object.
|
|
|
|
|
*
|
2024-05-13 11:16:27 +00:00
|
|
|
* @deprecated since 1.43, Use ObjectCacheFactory::getLocalClusterInstance()
|
|
|
|
|
*
|
2015-10-09 23:26:26 +00:00
|
|
|
* @since 1.27
|
|
|
|
|
* @return BagOStuff
|
|
|
|
|
*/
|
2015-10-19 17:56:41 +00:00
|
|
|
public static function getLocalClusterInstance() {
|
2024-05-13 11:16:27 +00:00
|
|
|
return MediaWikiServices::getInstance()->getObjectCacheFactory()
|
|
|
|
|
->getLocalClusterInstance();
|
2023-05-03 02:14:13 +00:00
|
|
|
}
|
|
|
|
|
|
2015-08-24 21:21:56 +00:00
|
|
|
/**
|
2023-09-07 15:12:17 +00:00
|
|
|
* @deprecated since 1.42, Use ObjectCacheFactory::clear() instead.
|
|
|
|
|
*
|
2015-08-24 21:21:56 +00:00
|
|
|
* Clear all the cached instances.
|
|
|
|
|
*/
|
|
|
|
|
public static function clear() {
|
2023-09-07 15:12:17 +00:00
|
|
|
MediaWikiServices::getInstance()->getObjectCacheFactory()->clear();
|
2015-08-24 21:21:56 +00:00
|
|
|
}
|
2005-04-09 10:30:45 +00:00
|
|
|
}
|