245bb387197ed96dde8aafdfdecbb628b92ab260
3 if (!defined('MEDIAWIKI')) die( "Not a valid entry point");
6 # FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
7 # It acts as a memcached server with no RAM, that is, all objects are
8 # cleared the moment they are set. All set operations succeed and all
9 # get operations return null.
10 class FakeMemCachedClient
{
11 function add ($key, $val, $exp = 0) { return true; }
12 function decr ($key, $amt=1) { return null; }
13 function delete ($key, $time = 0) { return false; }
14 function disconnect_all () { }
15 function enable_compress ($enable) { }
16 function forget_dead_hosts () { }
17 function get ($key) { return null; }
18 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
19 function incr ($key, $amt=1) { return null; }
20 function replace ($key, $value, $exp=0) { return false; }
21 function run_command ($sock, $cmd) { return null; }
22 function set ($key, $value, $exp=0){ return true; }
23 function set_compress_threshold ($thresh){ }
24 function set_debug ($dbg) { }
25 function set_servers ($list) { }
31 function &wfGetCache( $inputType ) {
32 global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug;
35 if ( $inputType == CACHE_ANYTHING
) {
37 $type = key( $wgCaches );
38 if ( $type === false ||
$type === CACHE_NONE
) {
45 if ( $type == CACHE_MEMCACHED
) {
46 if ( !array_key_exists( CACHE_MEMCACHED
, $wgCaches ) ){
47 require_once( 'memcached-client.php' );
49 class MemCachedClientforWiki
extends memcached
{
50 function _debugprint( $text ) {
51 wfDebug( "memcached: $text\n" );
55 $wgCaches[CACHE_DB
] = new MemCachedClientforWiki(
56 array('persistant' => true, 'compress_threshold' => 1500 ) );
57 $cache =& $wgCaches[CACHE_DB
];
58 $cache->set_servers( $wgMemCachedServers );
59 $cache->set_debug( $wgMemCachedDebug );
61 } elseif ( $type == CACHE_ACCEL
) {
62 if ( !array_key_exists( CACHE_ACCEL
, $wgCaches ) ) {
63 if ( function_exists( 'eaccelerator_get' ) ) {
64 require_once( 'BagOStuff.php' );
65 $wgCaches[CACHE_ACCEL
] = new eAccelBagOStuff
;
66 } elseif ( function_exists( 'mmcache_get' ) ) {
67 require_once( 'BagOStuff.php' );
68 $wgCaches[CACHE_ACCEL
] = new TurckBagOStuff
;
70 $wgCaches[CACHE_ACCEL
] = false;
73 if ( $wgCaches[CACHE_ACCEL
] !== false ) {
74 $cache =& $wgCaches[CACHE_ACCEL
];
78 if ( $type == CACHE_DB ||
( $inputType == CACHE_ANYTHING
&& $cache === false ) ) {
79 if ( !array_key_exists( CACHE_DB
, $wgCaches ) ) {
80 require_once( 'BagOStuff.php' );
81 $wgCaches[CACHE_DB
] = new MediaWikiBagOStuff('objectcache');
83 $cache =& $wgCaches[CACHE_DB
];
86 if ( $cache === false ) {
87 if ( !array_key_exists( CACHE_NONE
, $wgCaches ) ) {
88 $wgCaches[CACHE_NONE
] = new FakeMemCachedClient
;
90 $cache =& $wgCaches[CACHE_NONE
];
96 function &wfGetMainCache() {
97 global $wgMainCacheType;
98 return wfGetCache( $wgMainCacheType );
101 function &wfGetMessageCacheStorage() {
102 global $wgMessageCacheType;
103 return wfGetCache( $wgMessageCacheType );
106 function wfGetParserCacheStorage() {
107 global $wgParserCacheType;
108 return wfGetCache( $wgParserCacheType );