Merge "Set namespaces for dtp"
[mediawiki.git] / includes / objectcache / ObjectCache.php
blob21e08fe4bd978636de9e978f77adb6e42adc305c
1 <?php
2 /**
3 * Functions to get cache objects.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Cache
24 use MediaWiki\MediaWikiServices;
25 use Wikimedia\ObjectCache\BagOStuff;
27 /**
28 * @see ObjectCacheFactory
29 * @ingroup Cache
31 class ObjectCache {
32 /**
33 * @deprecated since 1.43; use ObjectCacheFactory instead.
34 * @var BagOStuff[] Map of (id => BagOStuff)
36 public static $instances = [];
38 /**
39 * Get a cached instance of the specified type of cache object.
41 * @deprecated since 1.43; use ObjectCacheFactory::getInstance instead.
43 * @param string|int $id A key in $wgObjectCaches.
44 * @return BagOStuff
46 public static function getInstance( $id ) {
47 return MediaWikiServices::getInstance()->getObjectCacheFactory()->getInstance( $id );
50 /**
51 * @see ObjectCacheFactory::newFromParams()
53 * @deprecated since 1.42, Use ObjectCacheFactory::newFromParams instead.
54 * @param array $params
56 * @return BagOStuff
58 public static function newFromParams( array $params ) {
59 return MediaWikiServices::getInstance()->getObjectCacheFactory()
60 ->newFromParams( $params );
63 /**
64 * Factory function for CACHE_ANYTHING (referenced by configuration)
66 * CACHE_ANYTHING means that stuff has to be cached, not caching is not an option.
67 * If a caching method is configured for any of the main caches ($wgMainCacheType,
68 * $wgMessageCacheType, $wgParserCacheType), then CACHE_ANYTHING will effectively
69 * be an alias to the configured cache choice for that.
70 * If no cache choice is configured (by default $wgMainCacheType is CACHE_NONE),
71 * then CACHE_ANYTHING will forward to CACHE_DB.
73 * @deprecated since 1.42, Use ObjectCacheFactory::getInstance( CACHE_ANYTHING );
75 * @return BagOStuff
77 public static function newAnything() {
78 return MediaWikiServices::getInstance()->getObjectCacheFactory()
79 ->getInstance( CACHE_ANYTHING );
82 /**
83 * @deprecated since 1.42, Use ObjectCacheFactory::getLocalServerInstance()
84 * @param int|string|array $fallback Fallback cache or parameter map with 'fallback'
85 * @return BagOStuff
86 * @since 1.27
88 public static function getLocalServerInstance( $fallback = CACHE_NONE ) {
89 return MediaWikiServices::getInstance()->getObjectCacheFactory()
90 ->getLocalServerInstance( $fallback );
93 /**
94 * Get the main cluster-local cache object.
96 * @deprecated since 1.43, Use ObjectCacheFactory::getLocalClusterInstance()
98 * @since 1.27
99 * @return BagOStuff
101 public static function getLocalClusterInstance() {
102 return MediaWikiServices::getInstance()->getObjectCacheFactory()
103 ->getLocalClusterInstance();
107 * @deprecated since 1.42, Use ObjectCacheFactory::clear() instead.
109 * Clear all the cached instances.
111 public static function clear() {
112 MediaWikiServices::getInstance()->getObjectCacheFactory()->clear();