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 if ( !class_exists( 'MemcachedClientforWiki' ) ) {
00056 class MemCachedClientforWiki extends memcached {
00057 function _debugprint( $text ) {
00058 wfDebug( "memcached: $text" );
00059 }
00060 }
00061 }
00062 $wgCaches[CACHE_MEMCACHED] = new MemCachedClientforWiki(
00063 array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
00064 $wgCaches[CACHE_MEMCACHED]->set_servers( $wgMemCachedServers );
00065 $wgCaches[CACHE_MEMCACHED]->set_debug( $wgMemCachedDebug );
00066 }
00067 $cache =& $wgCaches[CACHE_MEMCACHED];
00068 } elseif ( $type == CACHE_ACCEL ) {
00069 if ( !array_key_exists( CACHE_ACCEL, $wgCaches ) ) {
00070 if ( function_exists( 'eaccelerator_get' ) ) {
00071 $wgCaches[CACHE_ACCEL] = new eAccelBagOStuff;
00072 } elseif ( function_exists( 'apc_fetch') ) {
00073 $wgCaches[CACHE_ACCEL] = new APCBagOStuff;
00074 } elseif( function_exists( 'xcache_get' ) ) {
00075 $wgCaches[CACHE_ACCEL] = new XCacheBagOStuff();
00076 } elseif ( function_exists( 'mmcache_get' ) ) {
00077 $wgCaches[CACHE_ACCEL] = new TurckBagOStuff;
00078 } else {
00079 $wgCaches[CACHE_ACCEL] = false;
00080 }
00081 }
00082 if ( $wgCaches[CACHE_ACCEL] !== false ) {
00083 $cache =& $wgCaches[CACHE_ACCEL];
00084 }
00085 } elseif ( $type == CACHE_DBA ) {
00086 if ( !array_key_exists( CACHE_DBA, $wgCaches ) ) {
00087 $wgCaches[CACHE_DBA] = new DBABagOStuff;
00088 }
00089 $cache =& $wgCaches[CACHE_DBA];
00090 }
00091
00092 if ( $type == CACHE_DB || ( $inputType == CACHE_ANYTHING && $cache === false ) ) {
00093 if ( !array_key_exists( CACHE_DB, $wgCaches ) ) {
00094 $wgCaches[CACHE_DB] = new MediaWikiBagOStuff('objectcache');
00095 }
00096 $cache =& $wgCaches[CACHE_DB];
00097 }
00098
00099 if ( $cache === false ) {
00100 if ( !array_key_exists( CACHE_NONE, $wgCaches ) ) {
00101 $wgCaches[CACHE_NONE] = new FakeMemCachedClient;
00102 }
00103 $cache =& $wgCaches[CACHE_NONE];
00104 }
00105
00106 return $cache;
00107 }
00108
00110 function &wfGetMainCache() {
00111 global $wgMainCacheType;
00112 $ret =& wfGetCache( $wgMainCacheType );
00113 return $ret;
00114 }
00115
00117 function &wfGetMessageCacheStorage() {
00118 global $wgMessageCacheType;
00119 $ret =& wfGetCache( $wgMessageCacheType );
00120 return $ret;
00121 }
00122
00124 function &wfGetParserCacheStorage() {
00125 global $wgParserCacheType;
00126 $ret =& wfGetCache( $wgParserCacheType );
00127 return $ret;
00128 }