Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
ObjectCache
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 6
42
0.00% covered (danger)
0.00%
0 / 1
 getInstance
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 newFromParams
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 newAnything
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getLocalServerInstance
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getLocalClusterInstance
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 clear
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Functions to get cache objects.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup Cache
22 */
23
24use MediaWiki\MediaWikiServices;
25use Wikimedia\ObjectCache\BagOStuff;
26
27/**
28 * @see ObjectCacheFactory
29 * @ingroup Cache
30 */
31class ObjectCache {
32    /**
33     * @deprecated since 1.43; use ObjectCacheFactory instead.
34     * @var BagOStuff[] Map of (id => BagOStuff)
35     */
36    public static $instances = [];
37
38    /**
39     * Get a cached instance of the specified type of cache object.
40     *
41     * @deprecated since 1.43; use ObjectCacheFactory::getInstance instead.
42     *
43     * @param string|int $id A key in $wgObjectCaches.
44     * @return BagOStuff
45     */
46    public static function getInstance( $id ) {
47        return MediaWikiServices::getInstance()->getObjectCacheFactory()->getInstance( $id );
48    }
49
50    /**
51     * @see ObjectCacheFactory::newFromParams()
52     *
53     * @deprecated since 1.42, Use ObjectCacheFactory::newFromParams instead.
54     * @param array $params
55     *
56     * @return BagOStuff
57     */
58    public static function newFromParams( array $params ) {
59        return MediaWikiServices::getInstance()->getObjectCacheFactory()
60            ->newFromParams( $params );
61    }
62
63    /**
64     * Factory function for CACHE_ANYTHING (referenced by configuration)
65     *
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.
72     *
73     * @deprecated since 1.42, Use ObjectCacheFactory::getInstance( CACHE_ANYTHING );
74     *
75     * @return BagOStuff
76     */
77    public static function newAnything() {
78        return MediaWikiServices::getInstance()->getObjectCacheFactory()
79            ->getInstance( CACHE_ANYTHING );
80    }
81
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
87     */
88    public static function getLocalServerInstance( $fallback = CACHE_NONE ) {
89        return MediaWikiServices::getInstance()->getObjectCacheFactory()
90            ->getLocalServerInstance( $fallback );
91    }
92
93    /**
94     * Get the main cluster-local cache object.
95     *
96     * @deprecated since 1.43, Use ObjectCacheFactory::getLocalClusterInstance()
97     *
98     * @since 1.27
99     * @return BagOStuff
100     */
101    public static function getLocalClusterInstance() {
102        return MediaWikiServices::getInstance()->getObjectCacheFactory()
103            ->getLocalClusterInstance();
104    }
105
106    /**
107     * @deprecated since 1.42, Use ObjectCacheFactory::clear() instead.
108     *
109     * Clear all the cached instances.
110     */
111    public static function clear() {
112        MediaWikiServices::getInstance()->getObjectCacheFactory()->clear();
113    }
114}