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) { }
36 class ObjectCacheManager
{
38 function getCache( $inputType ) {
39 global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug, $wgMemCachedPersistent;
42 if ( $inputType == CACHE_ANYTHING
) {
44 $type = key( $wgCaches );
45 if ( $type === false ||
$type === CACHE_NONE
) {
52 if ( $type == CACHE_MEMCACHED
) {
53 if ( !array_key_exists( CACHE_MEMCACHED
, $wgCaches ) ){
54 $wgCaches[CACHE_DB
] = new MemCachedClientforWiki(
55 array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
56 $cache =& $wgCaches[CACHE_DB
];
57 $cache->set_servers( $wgMemCachedServers );
58 $cache->set_debug( $wgMemCachedDebug );
60 } elseif ( $type == CACHE_ACCEL
) {
61 if ( !array_key_exists( CACHE_ACCEL
, $wgCaches ) ) {
62 if ( function_exists( 'eaccelerator_get' ) ) {
63 $wgCaches[CACHE_ACCEL
] = new eAccelBagOStuff
;
64 } elseif ( function_exists( 'apc_fetch') ) {
65 $wgCaches[CACHE_ACCEL
] = new APCBagOStuff
;
66 } elseif ( function_exists( 'mmcache_get' ) ) {
67 $wgCaches[CACHE_ACCEL
] = new TurckBagOStuff
;
69 $wgCaches[CACHE_ACCEL
] = false;
72 if ( $wgCaches[CACHE_ACCEL
] !== false ) {
73 $cache =& $wgCaches[CACHE_ACCEL
];
77 if ( $type == CACHE_DB ||
( $inputType == CACHE_ANYTHING
&& $cache === false ) ) {
78 if ( !array_key_exists( CACHE_DB
, $wgCaches ) ) {
79 $wgCaches[CACHE_DB
] = new MediaWikiBagOStuff('objectcache');
81 $cache =& $wgCaches[CACHE_DB
];
84 if ( $cache === false ) {
85 if ( !array_key_exists( CACHE_NONE
, $wgCaches ) ) {
86 $wgCaches[CACHE_NONE
] = new FakeMemCachedClient
;
88 $cache =& $wgCaches[CACHE_NONE
];
95 function &getMainCache() {
96 global $wgMainCacheType;
97 $ret =& ObjectCacheManager
::getCache( $wgMainCacheType );
102 function &getMessageCache() {
103 global $wgMessageCacheType;
104 $ret =& ObjectCacheManager
::getCache( $wgMessageCacheType );
109 function &getParserCache() {
110 global $wgParserCacheType;
111 $ret =& ObjectCacheManager
::getCache( $wgParserCacheType );
117 class MemCachedClientforWiki
extends memcached
{
118 function _debugprint( $text ) {
119 wfDebug( "memcached: $text\n" );