00001 <?php
00014 class FakeMemCachedClient {
00015 function add ($key, $val, $exp = 0) { return true; }
00016 function decr ($key, $amt=1) { return null; }
00017 function delete ($key, $time = 0) { return false; }
00018 function disconnect_all () { }
00019 function enable_compress ($enable) { }
00020 function forget_dead_hosts () { }
00021 function get ($key) { return null; }
00022 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
00023 function incr ($key, $amt=1) { return null; }
00024 function replace ($key, $value, $exp=0) { return false; }
00025 function run_command ($sock, $cmd) { return null; }
00026 function set ($key, $value, $exp=0){ return true; }
00027 function set_compress_threshold ($thresh){ }
00028 function set_debug ($dbg) { }
00029 function set_servers ($list) { }
00030 }
00031
00032 global $wgCaches;
00033 $wgCaches = array();
00034
00039 function &wfGetCache( $inputType ) {
00040 global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug, $wgMemCachedPersistent;
00041 $cache = false;
00042
00043 if ( $inputType == CACHE_ANYTHING ) {
00044 reset( $wgCaches );
00045 $type = key( $wgCaches );
00046 if ( $type === false || $type === CACHE_NONE ) {
00047 $type = CACHE_DB;
00048 }
00049 } else {
00050 $type = $inputType;
00051 }
00052
00053 if ( $type == CACHE_MEMCACHED ) {
00054 if ( !array_key_exists( CACHE_MEMCACHED, $wgCaches ) ) {
00055 $wgCaches[CACHE_MEMCACHED] = new MemCachedClientforWiki(
00056 array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
00057 $wgCaches[CACHE_MEMCACHED]->set_servers( $wgMemCachedServers );
00058 $wgCaches[CACHE_MEMCACHED]->set_debug( $wgMemCachedDebug );
00059 }
00060 $cache =& $wgCaches[CACHE_MEMCACHED];
00061 } elseif ( $type == CACHE_ACCEL ) {
00062 if ( !array_key_exists( CACHE_ACCEL, $wgCaches ) ) {
00063 if ( function_exists( 'eaccelerator_get' ) ) {
00064 $wgCaches[CACHE_ACCEL] = new eAccelBagOStuff;
00065 } elseif ( function_exists( 'apc_fetch') ) {
00066 $wgCaches[CACHE_ACCEL] = new APCBagOStuff;
00067 } elseif( function_exists( 'xcache_get' ) ) {
00068 $wgCaches[CACHE_ACCEL] = new XCacheBagOStuff();
00069 } else {
00070 $wgCaches[CACHE_ACCEL] = false;
00071 }
00072 }
00073 if ( $wgCaches[CACHE_ACCEL] !== false ) {
00074 $cache =& $wgCaches[CACHE_ACCEL];
00075 }
00076 } elseif ( $type == CACHE_DBA ) {
00077 if ( !array_key_exists( CACHE_DBA, $wgCaches ) ) {
00078 $wgCaches[CACHE_DBA] = new DBABagOStuff;
00079 }
00080 $cache =& $wgCaches[CACHE_DBA];
00081 }
00082
00083 if ( $type == CACHE_DB || ( $inputType == CACHE_ANYTHING && $cache === false ) ) {
00084 if ( !array_key_exists( CACHE_DB, $wgCaches ) ) {
00085 $wgCaches[CACHE_DB] = new SqlBagOStuff('objectcache');
00086 }
00087 $cache =& $wgCaches[CACHE_DB];
00088 }
00089
00090 if ( $cache === false ) {
00091 if ( !array_key_exists( CACHE_NONE, $wgCaches ) ) {
00092 $wgCaches[CACHE_NONE] = new FakeMemCachedClient;
00093 }
00094 $cache =& $wgCaches[CACHE_NONE];
00095 }
00096
00097 return $cache;
00098 }
00099
00101 function &wfGetMainCache() {
00102 global $wgMainCacheType;
00103 $ret =& wfGetCache( $wgMainCacheType );
00104 return $ret;
00105 }
00106
00108 function &wfGetMessageCacheStorage() {
00109 global $wgMessageCacheType;
00110 $ret =& wfGetCache( $wgMessageCacheType );
00111 return $ret;
00112 }
00113
00115 function &wfGetParserCacheStorage() {
00116 global $wgParserCacheType;
00117 $ret =& wfGetCache( $wgParserCacheType );
00118 return $ret;
00119 }