8 * FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
9 * It acts as a memcached server with no RAM, that is, all objects are
10 * cleared the moment they are set. All set operations succeed and all
11 * get operations return null.
15 class FakeMemCachedClient
{
16 function add ($key, $val, $exp = 0) { return true; }
17 function decr ($key, $amt=1) { return null; }
18 function delete ($key, $time = 0) { return false; }
19 function disconnect_all () { }
20 function enable_compress ($enable) { }
21 function forget_dead_hosts () { }
22 function get ($key) { return null; }
23 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
24 function incr ($key, $amt=1) { return null; }
25 function replace ($key, $value, $exp=0) { return false; }
26 function run_command ($sock, $cmd) { return null; }
27 function set ($key, $value, $exp=0){ return true; }
28 function set_compress_threshold ($thresh){ }
29 function set_debug ($dbg) { }
30 function set_servers ($list) { }
37 function &wfGetCache( $inputType ) {
38 global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug, $wgMemCachedPersistent;
41 if ( $inputType == CACHE_ANYTHING
) {
43 $type = key( $wgCaches );
44 if ( $type === false ||
$type === CACHE_NONE
) {
51 if ( $type == CACHE_MEMCACHED
) {
52 if ( !array_key_exists( CACHE_MEMCACHED
, $wgCaches ) ){
53 require_once( 'memcached-client.php' );
55 if (!class_exists("MemcachedClientforWiki")) {
56 class MemCachedClientforWiki
extends memcached
{
57 function _debugprint( $text ) {
58 wfDebug( "memcached: $text\n" );
63 $wgCaches[CACHE_DB
] = new MemCachedClientforWiki(
64 array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
65 $cache =& $wgCaches[CACHE_DB
];
66 $cache->set_servers( $wgMemCachedServers );
67 $cache->set_debug( $wgMemCachedDebug );
69 } elseif ( $type == CACHE_ACCEL
) {
70 if ( !array_key_exists( CACHE_ACCEL
, $wgCaches ) ) {
71 if ( function_exists( 'eaccelerator_get' ) ) {
72 require_once( 'BagOStuff.php' );
73 $wgCaches[CACHE_ACCEL
] = new eAccelBagOStuff
;
74 } elseif ( function_exists( 'apc_fetch') ) {
75 require_once( 'BagOStuff.php' );
76 $wgCaches[CACHE_ACCEL
] = new APCBagOStuff
;
77 } elseif ( function_exists( 'mmcache_get' ) ) {
78 require_once( 'BagOStuff.php' );
79 $wgCaches[CACHE_ACCEL
] = new TurckBagOStuff
;
81 $wgCaches[CACHE_ACCEL
] = false;
84 if ( $wgCaches[CACHE_ACCEL
] !== false ) {
85 $cache =& $wgCaches[CACHE_ACCEL
];
87 } elseif ( $type == CACHE_DBA
) {
88 if ( !array_key_exists( CACHE_DBA
, $wgCaches ) ) {
89 require_once( 'BagOStuff.php' );
90 $wgCaches[CACHE_DBA
] = new DBABagOStuff
;
92 $cache =& $wgCaches[CACHE_DBA
];
95 if ( $type == CACHE_DB ||
( $inputType == CACHE_ANYTHING
&& $cache === false ) ) {
96 if ( !array_key_exists( CACHE_DB
, $wgCaches ) ) {
97 require_once( 'BagOStuff.php' );
98 $wgCaches[CACHE_DB
] = new MediaWikiBagOStuff('objectcache');
100 $cache =& $wgCaches[CACHE_DB
];
103 if ( $cache === false ) {
104 if ( !array_key_exists( CACHE_NONE
, $wgCaches ) ) {
105 $wgCaches[CACHE_NONE
] = new FakeMemCachedClient
;
107 $cache =& $wgCaches[CACHE_NONE
];
113 function &wfGetMainCache() {
114 global $wgMainCacheType;
115 $ret =& wfGetCache( $wgMainCacheType );
119 function &wfGetMessageCacheStorage() {
120 global $wgMessageCacheType;
121 $ret =& wfGetCache( $wgMessageCacheType );
125 function &wfGetParserCacheStorage() {
126 global $wgParserCacheType;
127 $ret =& wfGetCache( $wgParserCacheType );