Use Doxygen @addtogroup instead of phpdoc @package && @subpackage
[lhc/web/wiklou.git] / includes / ObjectCache.php
1 <?php
2 /**
3 * @addtogroup Cache
4 */
5
6 /**
7 * FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
8 * It acts as a memcached server with no RAM, that is, all objects are
9 * cleared the moment they are set. All set operations succeed and all
10 * get operations return null.
11 * @addtogroup Cache
12 */
13 class FakeMemCachedClient {
14 function add ($key, $val, $exp = 0) { return true; }
15 function decr ($key, $amt=1) { return null; }
16 function delete ($key, $time = 0) { return false; }
17 function disconnect_all () { }
18 function enable_compress ($enable) { }
19 function forget_dead_hosts () { }
20 function get ($key) { return null; }
21 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
22 function incr ($key, $amt=1) { return null; }
23 function replace ($key, $value, $exp=0) { return false; }
24 function run_command ($sock, $cmd) { return null; }
25 function set ($key, $value, $exp=0){ return true; }
26 function set_compress_threshold ($thresh){ }
27 function set_debug ($dbg) { }
28 function set_servers ($list) { }
29 }
30
31 global $wgCaches;
32 $wgCaches = array();
33
34 /** @todo document */
35 function &wfGetCache( $inputType ) {
36 global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug, $wgMemCachedPersistent;
37 $cache = false;
38
39 if ( $inputType == CACHE_ANYTHING ) {
40 reset( $wgCaches );
41 $type = key( $wgCaches );
42 if ( $type === false || $type === CACHE_NONE ) {
43 $type = CACHE_DB;
44 }
45 } else {
46 $type = $inputType;
47 }
48
49 if ( $type == CACHE_MEMCACHED ) {
50 if ( !array_key_exists( CACHE_MEMCACHED, $wgCaches ) ){
51 require_once( 'memcached-client.php' );
52
53 if (!class_exists("MemcachedClientforWiki")) {
54 class MemCachedClientforWiki extends memcached {
55 function _debugprint( $text ) {
56 wfDebug( "memcached: $text\n" );
57 }
58 }
59 }
60
61 $wgCaches[CACHE_DB] = new MemCachedClientforWiki(
62 array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
63 $cache =& $wgCaches[CACHE_DB];
64 $cache->set_servers( $wgMemCachedServers );
65 $cache->set_debug( $wgMemCachedDebug );
66 }
67 } elseif ( $type == CACHE_ACCEL ) {
68 if ( !array_key_exists( CACHE_ACCEL, $wgCaches ) ) {
69 if ( function_exists( 'eaccelerator_get' ) ) {
70 $wgCaches[CACHE_ACCEL] = new eAccelBagOStuff;
71 } elseif ( function_exists( 'apc_fetch') ) {
72 $wgCaches[CACHE_ACCEL] = new APCBagOStuff;
73 } elseif ( function_exists( 'mmcache_get' ) ) {
74 $wgCaches[CACHE_ACCEL] = new TurckBagOStuff;
75 } else {
76 $wgCaches[CACHE_ACCEL] = false;
77 }
78 }
79 if ( $wgCaches[CACHE_ACCEL] !== false ) {
80 $cache =& $wgCaches[CACHE_ACCEL];
81 }
82 } elseif ( $type == CACHE_DBA ) {
83 if ( !array_key_exists( CACHE_DBA, $wgCaches ) ) {
84 $wgCaches[CACHE_DBA] = new DBABagOStuff;
85 }
86 $cache =& $wgCaches[CACHE_DBA];
87 }
88
89 if ( $type == CACHE_DB || ( $inputType == CACHE_ANYTHING && $cache === false ) ) {
90 if ( !array_key_exists( CACHE_DB, $wgCaches ) ) {
91 $wgCaches[CACHE_DB] = new MediaWikiBagOStuff('objectcache');
92 }
93 $cache =& $wgCaches[CACHE_DB];
94 }
95
96 if ( $cache === false ) {
97 if ( !array_key_exists( CACHE_NONE, $wgCaches ) ) {
98 $wgCaches[CACHE_NONE] = new FakeMemCachedClient;
99 }
100 $cache =& $wgCaches[CACHE_NONE];
101 }
102
103 return $cache;
104 }
105
106 function &wfGetMainCache() {
107 global $wgMainCacheType;
108 $ret =& wfGetCache( $wgMainCacheType );
109 return $ret;
110 }
111
112 function &wfGetMessageCacheStorage() {
113 global $wgMessageCacheType;
114 $ret =& wfGetCache( $wgMessageCacheType );
115 return $ret;
116 }
117
118 function &wfGetParserCacheStorage() {
119 global $wgParserCacheType;
120 $ret =& wfGetCache( $wgParserCacheType );
121 return $ret;
122 }
123
124 ?>