3 * Functions to get cache objects
10 * FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
11 * It acts as a memcached server with no RAM, that is, all objects are
12 * cleared the moment they are set. All set operations succeed and all
13 * get operations return null.
16 class FakeMemCachedClient
{
17 function add ($key, $val, $exp = 0) { return true; }
18 function decr ($key, $amt=1) { return null; }
19 function delete ($key, $time = 0) { return false; }
20 function disconnect_all () { }
21 function enable_compress ($enable) { }
22 function forget_dead_hosts () { }
23 function get ($key) { return null; }
24 function get_multi ($keys) { return array_pad(array(), count($keys), null); }
25 function incr ($key, $amt=1) { return null; }
26 function replace ($key, $value, $exp=0) { return false; }
27 function run_command ($sock, $cmd) { return null; }
28 function set ($key, $value, $exp=0){ return true; }
29 function set_compress_threshold ($thresh){ }
30 function set_debug ($dbg) { }
31 function set_servers ($list) { }
39 * @param $inputType Integer: cache type, one the the CACHE_* constants.
41 function &wfGetCache( $inputType ) {
42 global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug, $wgMemCachedPersistent;
45 if ( $inputType == CACHE_ANYTHING
) {
47 $type = key( $wgCaches );
48 if ( $type === false ||
$type === CACHE_NONE
) {
55 if ( $type == CACHE_MEMCACHED
) {
56 if ( !array_key_exists( CACHE_MEMCACHED
, $wgCaches ) ) {
57 $wgCaches[CACHE_MEMCACHED
] = new MemCachedClientforWiki(
58 array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
59 $wgCaches[CACHE_MEMCACHED
]->set_servers( $wgMemCachedServers );
60 $wgCaches[CACHE_MEMCACHED
]->set_debug( $wgMemCachedDebug );
62 $cache =& $wgCaches[CACHE_MEMCACHED
];
63 } elseif ( $type == CACHE_ACCEL
) {
64 if ( !array_key_exists( CACHE_ACCEL
, $wgCaches ) ) {
65 if ( function_exists( 'eaccelerator_get' ) ) {
66 $wgCaches[CACHE_ACCEL
] = new eAccelBagOStuff
;
67 } elseif ( function_exists( 'apc_fetch') ) {
68 $wgCaches[CACHE_ACCEL
] = new APCBagOStuff
;
69 } elseif( function_exists( 'xcache_get' ) ) {
70 $wgCaches[CACHE_ACCEL
] = new XCacheBagOStuff();
71 } elseif( function_exists( 'wincache_ucache_get' ) ) {
72 $wgCaches[CACHE_ACCEL
] = new WinCacheBagOStuff();
74 $wgCaches[CACHE_ACCEL
] = false;
77 if ( $wgCaches[CACHE_ACCEL
] !== false ) {
78 $cache =& $wgCaches[CACHE_ACCEL
];
80 } elseif ( $type == CACHE_DBA
) {
81 if ( !array_key_exists( CACHE_DBA
, $wgCaches ) ) {
82 $wgCaches[CACHE_DBA
] = new DBABagOStuff
;
84 $cache =& $wgCaches[CACHE_DBA
];
87 if ( $type == CACHE_DB ||
( $inputType == CACHE_ANYTHING
&& $cache === false ) ) {
88 if ( !array_key_exists( CACHE_DB
, $wgCaches ) ) {
89 $wgCaches[CACHE_DB
] = new SqlBagOStuff('objectcache');
91 $cache =& $wgCaches[CACHE_DB
];
94 if ( $cache === false ) {
95 if ( !array_key_exists( CACHE_NONE
, $wgCaches ) ) {
96 $wgCaches[CACHE_NONE
] = new FakeMemCachedClient
;
98 $cache =& $wgCaches[CACHE_NONE
];
104 /** Get the main cache object */
105 function &wfGetMainCache() {
106 global $wgMainCacheType;
107 $ret =& wfGetCache( $wgMainCacheType );
111 /** Get the cache object used by the message cache */
112 function &wfGetMessageCacheStorage() {
113 global $wgMessageCacheType;
114 $ret =& wfGetCache( $wgMessageCacheType );
118 /** Get the cache object used by the parser cache */
119 function &wfGetParserCacheStorage() {
120 global $wgParserCacheType;
121 $ret =& wfGetCache( $wgParserCacheType );