* OracleInstaller now also supports installation with (requested by Tim):
[mediawiki.git] / includes / ObjectCache.php
blob6824d21e74dc44350c1ebd0d552794688699a83b
1 <?php
2 /**
3 * Functions to get cache objects
5 * @file
6 * @ingroup Cache
7 */
9 /**
10 * FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
11 * It acts as a memcached server with no RAM, that is, all objects are
12 * cleared the moment they are set. All set operations succeed and all
13 * get operations return null.
14 * @ingroup Cache
16 class FakeMemCachedClient {
17 function add ($key, $val, $exp = 0) { return true; }
18 function decr ($key, $amt=1) { return null; }
19 function delete ($key, $time = 0) { return false; }
20 function disconnect_all () { }
21 function enable_compress ($enable) { }
22 function forget_dead_hosts () { }
23 function get ($key) { return null; }
24 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
25 function incr ($key, $amt=1) { return null; }
26 function replace ($key, $value, $exp=0) { return false; }
27 function run_command ($sock, $cmd) { return null; }
28 function set ($key, $value, $exp=0){ return true; }
29 function set_compress_threshold ($thresh){ }
30 function set_debug ($dbg) { }
31 function set_servers ($list) { }
34 global $wgCaches;
35 $wgCaches = array();
37 /**
38 * Get a cache object.
39 * @param $inputType Integer: cache type, one the the CACHE_* constants.
41 * @return BagOStuff
43 function &wfGetCache( $inputType ) {
44 global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug, $wgMemCachedPersistent;
45 $cache = false;
47 if ( $inputType == CACHE_ANYTHING ) {
48 reset( $wgCaches );
49 $type = key( $wgCaches );
50 if ( $type === false || $type === CACHE_NONE ) {
51 $type = CACHE_DB;
53 } else {
54 $type = $inputType;
57 if ( $type == CACHE_MEMCACHED ) {
58 if ( !array_key_exists( CACHE_MEMCACHED, $wgCaches ) ) {
59 $wgCaches[CACHE_MEMCACHED] = new MemCachedClientforWiki(
60 array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
61 $wgCaches[CACHE_MEMCACHED]->set_servers( $wgMemCachedServers );
62 $wgCaches[CACHE_MEMCACHED]->set_debug( $wgMemCachedDebug );
64 $cache =& $wgCaches[CACHE_MEMCACHED];
65 } elseif ( $type == CACHE_ACCEL ) {
66 if ( !array_key_exists( CACHE_ACCEL, $wgCaches ) ) {
67 if ( function_exists( 'eaccelerator_get' ) ) {
68 $wgCaches[CACHE_ACCEL] = new eAccelBagOStuff;
69 } elseif ( function_exists( 'apc_fetch') ) {
70 $wgCaches[CACHE_ACCEL] = new APCBagOStuff;
71 } elseif( function_exists( 'xcache_get' ) ) {
72 $wgCaches[CACHE_ACCEL] = new XCacheBagOStuff();
73 } elseif( function_exists( 'wincache_ucache_get' ) ) {
74 $wgCaches[CACHE_ACCEL] = new WinCacheBagOStuff();
75 } else {
76 $wgCaches[CACHE_ACCEL] = false;
79 if ( $wgCaches[CACHE_ACCEL] !== false ) {
80 $cache =& $wgCaches[CACHE_ACCEL];
82 } elseif ( $type == CACHE_DBA ) {
83 if ( !array_key_exists( CACHE_DBA, $wgCaches ) ) {
84 $wgCaches[CACHE_DBA] = new DBABagOStuff;
86 $cache =& $wgCaches[CACHE_DBA];
89 if ( $type == CACHE_DB || ( $inputType == CACHE_ANYTHING && $cache === false ) ) {
90 if ( !array_key_exists( CACHE_DB, $wgCaches ) ) {
91 $wgCaches[CACHE_DB] = new SqlBagOStuff('objectcache');
93 $cache =& $wgCaches[CACHE_DB];
96 if ( $cache === false ) {
97 if ( !array_key_exists( CACHE_NONE, $wgCaches ) ) {
98 $wgCaches[CACHE_NONE] = new FakeMemCachedClient;
100 $cache =& $wgCaches[CACHE_NONE];
103 return $cache;
106 /** Get the main cache object */
107 function &wfGetMainCache() {
108 global $wgMainCacheType;
109 $ret =& wfGetCache( $wgMainCacheType );
110 return $ret;
113 /** Get the cache object used by the message cache */
114 function &wfGetMessageCacheStorage() {
115 global $wgMessageCacheType;
116 $ret =& wfGetCache( $wgMessageCacheType );
117 return $ret;
120 /** Get the cache object used by the parser cache */
121 function &wfGetParserCacheStorage() {
122 global $wgParserCacheType;
123 $ret =& wfGetCache( $wgParserCacheType );
124 return $ret;