Rewrite ajaxwatch.js to use the API watch action, and JQuery. Allows it to be used...
[lhc/web/wiklou.git] / includes / ObjectCache.php
1 <?php
2 /**
3 * @file
4 * @ingroup Cache
5 */
6
7 /**
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.
12 * @ingroup Cache
13 */
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) { }
30 }
31
32 global $wgCaches;
33 $wgCaches = array();
34
35 /**
36 * Get a cache object.
37 * @param $inputType Integer: cache type, one the the CACHE_* constants.
38 */
39 function &wfGetCache( $inputType ) {
40 global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug, $wgMemCachedPersistent;
41 $cache = false;
42
43 if ( $inputType == CACHE_ANYTHING ) {
44 reset( $wgCaches );
45 $type = key( $wgCaches );
46 if ( $type === false || $type === CACHE_NONE ) {
47 $type = CACHE_DB;
48 }
49 } else {
50 $type = $inputType;
51 }
52
53 if ( $type == CACHE_MEMCACHED ) {
54 if ( !array_key_exists( CACHE_MEMCACHED, $wgCaches ) ) {
55 $wgCaches[CACHE_MEMCACHED] = new MemCachedClientforWiki(
56 array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
57 $wgCaches[CACHE_MEMCACHED]->set_servers( $wgMemCachedServers );
58 $wgCaches[CACHE_MEMCACHED]->set_debug( $wgMemCachedDebug );
59 }
60 $cache =& $wgCaches[CACHE_MEMCACHED];
61 } elseif ( $type == CACHE_ACCEL ) {
62 if ( !array_key_exists( CACHE_ACCEL, $wgCaches ) ) {
63 if ( function_exists( 'eaccelerator_get' ) ) {
64 $wgCaches[CACHE_ACCEL] = new eAccelBagOStuff;
65 } elseif ( function_exists( 'apc_fetch') ) {
66 $wgCaches[CACHE_ACCEL] = new APCBagOStuff;
67 } elseif( function_exists( 'xcache_get' ) ) {
68 $wgCaches[CACHE_ACCEL] = new XCacheBagOStuff();
69 } else {
70 $wgCaches[CACHE_ACCEL] = false;
71 }
72 }
73 if ( $wgCaches[CACHE_ACCEL] !== false ) {
74 $cache =& $wgCaches[CACHE_ACCEL];
75 }
76 } elseif ( $type == CACHE_DBA ) {
77 if ( !array_key_exists( CACHE_DBA, $wgCaches ) ) {
78 $wgCaches[CACHE_DBA] = new DBABagOStuff;
79 }
80 $cache =& $wgCaches[CACHE_DBA];
81 }
82
83 if ( $type == CACHE_DB || ( $inputType == CACHE_ANYTHING && $cache === false ) ) {
84 if ( !array_key_exists( CACHE_DB, $wgCaches ) ) {
85 $wgCaches[CACHE_DB] = new SqlBagOStuff('objectcache');
86 }
87 $cache =& $wgCaches[CACHE_DB];
88 }
89
90 if ( $cache === false ) {
91 if ( !array_key_exists( CACHE_NONE, $wgCaches ) ) {
92 $wgCaches[CACHE_NONE] = new FakeMemCachedClient;
93 }
94 $cache =& $wgCaches[CACHE_NONE];
95 }
96
97 return $cache;
98 }
99
100 /** Get the main cache object */
101 function &wfGetMainCache() {
102 global $wgMainCacheType;
103 $ret =& wfGetCache( $wgMainCacheType );
104 return $ret;
105 }
106
107 /** Get the cache object used by the message cache */
108 function &wfGetMessageCacheStorage() {
109 global $wgMessageCacheType;
110 $ret =& wfGetCache( $wgMessageCacheType );
111 return $ret;
112 }
113
114 /** Get the cache object used by the parser cache */
115 function &wfGetParserCacheStorage() {
116 global $wgParserCacheType;
117 $ret =& wfGetCache( $wgParserCacheType );
118 return $ret;
119 }