3 * Functions to get cache objects
14 * @param $inputType Integer: cache type, one the the CACHE_* constants.
18 function &wfGetCache( $inputType ) {
19 global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug, $wgMemCachedPersistent;
22 if ( $inputType == CACHE_ANYTHING
) {
24 $type = key( $wgCaches );
25 if ( $type === false ||
$type === CACHE_NONE
) {
32 if ( $type == CACHE_MEMCACHED
) {
33 if ( !array_key_exists( CACHE_MEMCACHED
, $wgCaches ) ) {
34 $wgCaches[CACHE_MEMCACHED
] = new MemCachedClientforWiki(
35 array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
36 $wgCaches[CACHE_MEMCACHED
]->set_servers( $wgMemCachedServers );
37 $wgCaches[CACHE_MEMCACHED
]->set_debug( $wgMemCachedDebug );
39 $cache =& $wgCaches[CACHE_MEMCACHED
];
40 } elseif ( $type == CACHE_ACCEL
) {
41 if ( !array_key_exists( CACHE_ACCEL
, $wgCaches ) ) {
42 if ( function_exists( 'eaccelerator_get' ) ) {
43 $wgCaches[CACHE_ACCEL
] = new eAccelBagOStuff
;
44 } elseif ( function_exists( 'apc_fetch') ) {
45 $wgCaches[CACHE_ACCEL
] = new APCBagOStuff
;
46 } elseif( function_exists( 'xcache_get' ) ) {
47 $wgCaches[CACHE_ACCEL
] = new XCacheBagOStuff();
48 } elseif( function_exists( 'wincache_ucache_get' ) ) {
49 $wgCaches[CACHE_ACCEL
] = new WinCacheBagOStuff();
51 $wgCaches[CACHE_ACCEL
] = false;
54 if ( $wgCaches[CACHE_ACCEL
] !== false ) {
55 $cache =& $wgCaches[CACHE_ACCEL
];
57 } elseif ( $type == CACHE_DBA
) {
58 if ( !array_key_exists( CACHE_DBA
, $wgCaches ) ) {
59 $wgCaches[CACHE_DBA
] = new DBABagOStuff
;
61 $cache =& $wgCaches[CACHE_DBA
];
64 if ( $type == CACHE_DB ||
( $inputType == CACHE_ANYTHING
&& $cache === false ) ) {
65 if ( !array_key_exists( CACHE_DB
, $wgCaches ) ) {
66 $wgCaches[CACHE_DB
] = new SqlBagOStuff('objectcache');
68 $cache =& $wgCaches[CACHE_DB
];
71 if ( $cache === false ) {
72 if ( !array_key_exists( CACHE_NONE
, $wgCaches ) ) {
73 $wgCaches[CACHE_NONE
] = new FakeMemCachedClient
;
75 $cache =& $wgCaches[CACHE_NONE
];
81 /** Get the main cache object */
82 function &wfGetMainCache() {
83 global $wgMainCacheType;
84 $ret =& wfGetCache( $wgMainCacheType );
88 /** Get the cache object used by the message cache */
89 function &wfGetMessageCacheStorage() {
90 global $wgMessageCacheType;
91 $ret =& wfGetCache( $wgMessageCacheType );
95 /** Get the cache object used by the parser cache */
96 function &wfGetParserCacheStorage() {
97 global $wgParserCacheType;
98 $ret =& wfGetCache( $wgParserCacheType );