More renames and splits for objectcache reorganisation.
[lhc/web/wiklou.git] / includes / objectcache / ObjectCache.php
1 <?php
2 /**
3 * Functions to get cache objects
4 *
5 * @file
6 * @ingroup Cache
7 */
8
9 global $wgCaches;
10 $wgCaches = array();
11
12 /**
13 * Get a cache object.
14 * @param $inputType Integer: cache type, one the the CACHE_* constants.
15 *
16 * @return BagOStuff
17 */
18 function &wfGetCache( $inputType ) {
19 global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug, $wgMemCachedPersistent;
20 $cache = false;
21
22 if ( $inputType == CACHE_ANYTHING ) {
23 reset( $wgCaches );
24 $type = key( $wgCaches );
25 if ( $type === false || $type === CACHE_NONE ) {
26 $type = CACHE_DB;
27 }
28 } else {
29 $type = $inputType;
30 }
31
32 if ( $type == CACHE_MEMCACHED ) {
33 if ( !array_key_exists( CACHE_MEMCACHED, $wgCaches ) ) {
34 $wgCaches[CACHE_MEMCACHED] = new MemCachedClientforWiki(
35 array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
36 $wgCaches[CACHE_MEMCACHED]->set_servers( $wgMemCachedServers );
37 $wgCaches[CACHE_MEMCACHED]->set_debug( $wgMemCachedDebug );
38 }
39 $cache =& $wgCaches[CACHE_MEMCACHED];
40 } elseif ( $type == CACHE_ACCEL ) {
41 if ( !array_key_exists( CACHE_ACCEL, $wgCaches ) ) {
42 if ( function_exists( 'eaccelerator_get' ) ) {
43 $wgCaches[CACHE_ACCEL] = new eAccelBagOStuff;
44 } elseif ( function_exists( 'apc_fetch') ) {
45 $wgCaches[CACHE_ACCEL] = new APCBagOStuff;
46 } elseif( function_exists( 'xcache_get' ) ) {
47 $wgCaches[CACHE_ACCEL] = new XCacheBagOStuff();
48 } elseif( function_exists( 'wincache_ucache_get' ) ) {
49 $wgCaches[CACHE_ACCEL] = new WinCacheBagOStuff();
50 } else {
51 $wgCaches[CACHE_ACCEL] = false;
52 }
53 }
54 if ( $wgCaches[CACHE_ACCEL] !== false ) {
55 $cache =& $wgCaches[CACHE_ACCEL];
56 }
57 } elseif ( $type == CACHE_DBA ) {
58 if ( !array_key_exists( CACHE_DBA, $wgCaches ) ) {
59 $wgCaches[CACHE_DBA] = new DBABagOStuff;
60 }
61 $cache =& $wgCaches[CACHE_DBA];
62 }
63
64 if ( $type == CACHE_DB || ( $inputType == CACHE_ANYTHING && $cache === false ) ) {
65 if ( !array_key_exists( CACHE_DB, $wgCaches ) ) {
66 $wgCaches[CACHE_DB] = new SqlBagOStuff('objectcache');
67 }
68 $cache =& $wgCaches[CACHE_DB];
69 }
70
71 if ( $cache === false ) {
72 if ( !array_key_exists( CACHE_NONE, $wgCaches ) ) {
73 $wgCaches[CACHE_NONE] = new FakeMemCachedClient;
74 }
75 $cache =& $wgCaches[CACHE_NONE];
76 }
77
78 return $cache;
79 }
80
81 /** Get the main cache object */
82 function &wfGetMainCache() {
83 global $wgMainCacheType;
84 $ret =& wfGetCache( $wgMainCacheType );
85 return $ret;
86 }
87
88 /** Get the cache object used by the message cache */
89 function &wfGetMessageCacheStorage() {
90 global $wgMessageCacheType;
91 $ret =& wfGetCache( $wgMessageCacheType );
92 return $ret;
93 }
94
95 /** Get the cache object used by the parser cache */
96 function &wfGetParserCacheStorage() {
97 global $wgParserCacheType;
98 $ret =& wfGetCache( $wgParserCacheType );
99 return $ret;
100 }