7 if (!defined('MEDIAWIKI')) die( "Not a valid entry point\n");
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 class FakeMemCachedClient
{
15 function add ($key, $val, $exp = 0) { return true; }
16 function decr ($key, $amt=1) { return null; }
17 function delete ($key, $time = 0) { return false; }
18 function disconnect_all () { }
19 function enable_compress ($enable) { }
20 function forget_dead_hosts () { }
21 function get ($key) { return null; }
22 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
23 function incr ($key, $amt=1) { return null; }
24 function replace ($key, $value, $exp=0) { return false; }
25 function run_command ($sock, $cmd) { return null; }
26 function set ($key, $value, $exp=0){ return true; }
27 function set_compress_threshold ($thresh){ }
28 function set_debug ($dbg) { }
29 function set_servers ($list) { }
35 function &wfGetCache( $inputType ) {
36 global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug;
39 if ( $inputType == CACHE_ANYTHING
) {
41 $type = key( $wgCaches );
42 if ( $type === false ||
$type === CACHE_NONE
) {
49 if ( $type == CACHE_MEMCACHED
) {
50 if ( !array_key_exists( CACHE_MEMCACHED
, $wgCaches ) ){
51 require_once( 'memcached-client.php' );
53 class MemCachedClientforWiki
extends memcached
{
54 function _debugprint( $text ) {
55 wfDebug( "memcached: $text\n" );
59 $wgCaches[CACHE_DB
] = new MemCachedClientforWiki(
60 array('persistant' => true, 'compress_threshold' => 1500 ) );
61 $cache =& $wgCaches[CACHE_DB
];
62 $cache->set_servers( $wgMemCachedServers );
63 $cache->set_debug( $wgMemCachedDebug );
65 } elseif ( $type == CACHE_ACCEL
) {
66 if ( !array_key_exists( CACHE_ACCEL
, $wgCaches ) ) {
67 if ( function_exists( 'eaccelerator_get' ) ) {
68 require_once( 'BagOStuff.php' );
69 $wgCaches[CACHE_ACCEL
] = new eAccelBagOStuff
;
70 } elseif ( function_exists( 'mmcache_get' ) ) {
71 require_once( 'BagOStuff.php' );
72 $wgCaches[CACHE_ACCEL
] = new TurckBagOStuff
;
74 $wgCaches[CACHE_ACCEL
] = false;
77 if ( $wgCaches[CACHE_ACCEL
] !== false ) {
78 $cache =& $wgCaches[CACHE_ACCEL
];
82 if ( $type == CACHE_DB ||
( $inputType == CACHE_ANYTHING
&& $cache === false ) ) {
83 if ( !array_key_exists( CACHE_DB
, $wgCaches ) ) {
84 require_once( 'BagOStuff.php' );
85 $wgCaches[CACHE_DB
] = new MediaWikiBagOStuff('objectcache');
87 $cache =& $wgCaches[CACHE_DB
];
90 if ( $cache === false ) {
91 if ( !array_key_exists( CACHE_NONE
, $wgCaches ) ) {
92 $wgCaches[CACHE_NONE
] = new FakeMemCachedClient
;
94 $cache =& $wgCaches[CACHE_NONE
];
100 function &wfGetMainCache() {
101 global $wgMainCacheType;
102 return wfGetCache( $wgMainCacheType );
105 function &wfGetMessageCacheStorage() {
106 global $wgMessageCacheType;
107 return wfGetCache( $wgMessageCacheType );
110 function wfGetParserCacheStorage() {
111 global $wgParserCacheType;
112 return wfGetCache( $wgParserCacheType );