Update the Chinese conversion tables.
[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 } elseif( function_exists( 'wincache_ucache_get' ) ) {
70 $wgCaches[CACHE_ACCEL] = new WinCacheBagOStuff();
71 } else {
72 $wgCaches[CACHE_ACCEL] = false;
73 }
74 }
75 if ( $wgCaches[CACHE_ACCEL] !== false ) {
76 $cache =& $wgCaches[CACHE_ACCEL];
77 }
78 } elseif ( $type == CACHE_DBA ) {
79 if ( !array_key_exists( CACHE_DBA, $wgCaches ) ) {
80 $wgCaches[CACHE_DBA] = new DBABagOStuff;
81 }
82 $cache =& $wgCaches[CACHE_DBA];
83 }
84
85 if ( $type == CACHE_DB || ( $inputType == CACHE_ANYTHING && $cache === false ) ) {
86 if ( !array_key_exists( CACHE_DB, $wgCaches ) ) {
87 $wgCaches[CACHE_DB] = new SqlBagOStuff('objectcache');
88 }
89 $cache =& $wgCaches[CACHE_DB];
90 }
91
92 if ( $cache === false ) {
93 if ( !array_key_exists( CACHE_NONE, $wgCaches ) ) {
94 $wgCaches[CACHE_NONE] = new FakeMemCachedClient;
95 }
96 $cache =& $wgCaches[CACHE_NONE];
97 }
98
99 return $cache;
100 }
101
102 /** Get the main cache object */
103 function &wfGetMainCache() {
104 global $wgMainCacheType;
105 $ret =& wfGetCache( $wgMainCacheType );
106 return $ret;
107 }
108
109 /** Get the cache object used by the message cache */
110 function &wfGetMessageCacheStorage() {
111 global $wgMessageCacheType;
112 $ret =& wfGetCache( $wgMessageCacheType );
113 return $ret;
114 }
115
116 /** Get the cache object used by the parser cache */
117 function &wfGetParserCacheStorage() {
118 global $wgParserCacheType;
119 $ret =& wfGetCache( $wgParserCacheType );
120 return $ret;
121 }