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