2004-05-09 05:12:55 +00:00
|
|
|
<?php
|
2005-04-12 01:29:21 +00:00
|
|
|
/**
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup Cache
|
2005-04-12 01:29:21 +00:00
|
|
|
*/
|
2004-08-21 13:59:48 +00:00
|
|
|
|
2005-07-05 21:22:25 +00:00
|
|
|
/**
|
|
|
|
|
* FakeMemCachedClient imitates the API of memcached-client v. 0.1.2.
|
|
|
|
|
* It acts as a memcached server with no RAM, that is, all objects are
|
|
|
|
|
* cleared the moment they are set. All set operations succeed and all
|
|
|
|
|
* get operations return null.
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Cache
|
2005-07-05 21:22:25 +00:00
|
|
|
*/
|
2005-04-09 10:30:45 +00:00
|
|
|
class FakeMemCachedClient {
|
|
|
|
|
function add ($key, $val, $exp = 0) { return true; }
|
|
|
|
|
function decr ($key, $amt=1) { return null; }
|
|
|
|
|
function delete ($key, $time = 0) { return false; }
|
|
|
|
|
function disconnect_all () { }
|
|
|
|
|
function enable_compress ($enable) { }
|
|
|
|
|
function forget_dead_hosts () { }
|
|
|
|
|
function get ($key) { return null; }
|
|
|
|
|
function get_multi ($keys) { return array_pad(array(), count($keys), null); }
|
|
|
|
|
function incr ($key, $amt=1) { return null; }
|
|
|
|
|
function replace ($key, $value, $exp=0) { return false; }
|
|
|
|
|
function run_command ($sock, $cmd) { return null; }
|
|
|
|
|
function set ($key, $value, $exp=0){ return true; }
|
|
|
|
|
function set_compress_threshold ($thresh){ }
|
|
|
|
|
function set_debug ($dbg) { }
|
|
|
|
|
function set_servers ($list) { }
|
2004-05-09 05:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
2005-04-09 10:30:45 +00:00
|
|
|
global $wgCaches;
|
|
|
|
|
$wgCaches = array();
|
2004-09-02 23:28:24 +00:00
|
|
|
|
2008-11-14 22:45:32 +00:00
|
|
|
/**
|
|
|
|
|
* Get a cache object.
|
|
|
|
|
* @param int $inputType cache type, one the the CACHE_* constants.
|
|
|
|
|
*/
|
2006-06-01 08:19:02 +00:00
|
|
|
function &wfGetCache( $inputType ) {
|
|
|
|
|
global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug, $wgMemCachedPersistent;
|
|
|
|
|
$cache = false;
|
2004-08-27 13:40:27 +00:00
|
|
|
|
2006-06-01 08:19:02 +00:00
|
|
|
if ( $inputType == CACHE_ANYTHING ) {
|
|
|
|
|
reset( $wgCaches );
|
|
|
|
|
$type = key( $wgCaches );
|
|
|
|
|
if ( $type === false || $type === CACHE_NONE ) {
|
|
|
|
|
$type = CACHE_DB;
|
2004-05-09 05:12:55 +00:00
|
|
|
}
|
2006-06-01 08:19:02 +00:00
|
|
|
} else {
|
|
|
|
|
$type = $inputType;
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2006-06-01 08:19:02 +00:00
|
|
|
if ( $type == CACHE_MEMCACHED ) {
|
2008-09-27 22:51:59 +00:00
|
|
|
if ( !array_key_exists( CACHE_MEMCACHED, $wgCaches ) ) {
|
|
|
|
|
$wgCaches[CACHE_MEMCACHED] = new MemCachedClientforWiki(
|
2006-06-01 08:19:02 +00:00
|
|
|
array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) );
|
2008-09-27 22:51:59 +00:00
|
|
|
$wgCaches[CACHE_MEMCACHED]->set_servers( $wgMemCachedServers );
|
|
|
|
|
$wgCaches[CACHE_MEMCACHED]->set_debug( $wgMemCachedDebug );
|
2005-04-09 10:30:45 +00:00
|
|
|
}
|
2008-09-27 22:51:59 +00:00
|
|
|
$cache =& $wgCaches[CACHE_MEMCACHED];
|
2006-06-01 08:19:02 +00:00
|
|
|
} elseif ( $type == CACHE_ACCEL ) {
|
|
|
|
|
if ( !array_key_exists( CACHE_ACCEL, $wgCaches ) ) {
|
|
|
|
|
if ( function_exists( 'eaccelerator_get' ) ) {
|
|
|
|
|
$wgCaches[CACHE_ACCEL] = new eAccelBagOStuff;
|
|
|
|
|
} elseif ( function_exists( 'apc_fetch') ) {
|
|
|
|
|
$wgCaches[CACHE_ACCEL] = new APCBagOStuff;
|
2007-06-08 15:56:32 +00:00
|
|
|
} elseif( function_exists( 'xcache_get' ) ) {
|
|
|
|
|
$wgCaches[CACHE_ACCEL] = new XCacheBagOStuff();
|
2006-06-01 08:19:02 +00:00
|
|
|
} elseif ( function_exists( 'mmcache_get' ) ) {
|
|
|
|
|
$wgCaches[CACHE_ACCEL] = new TurckBagOStuff;
|
|
|
|
|
} else {
|
|
|
|
|
$wgCaches[CACHE_ACCEL] = false;
|
2004-11-22 01:33:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
2006-06-01 08:19:02 +00:00
|
|
|
if ( $wgCaches[CACHE_ACCEL] !== false ) {
|
|
|
|
|
$cache =& $wgCaches[CACHE_ACCEL];
|
|
|
|
|
}
|
2006-07-26 07:15:39 +00:00
|
|
|
} elseif ( $type == CACHE_DBA ) {
|
|
|
|
|
if ( !array_key_exists( CACHE_DBA, $wgCaches ) ) {
|
|
|
|
|
$wgCaches[CACHE_DBA] = new DBABagOStuff;
|
|
|
|
|
}
|
|
|
|
|
$cache =& $wgCaches[CACHE_DBA];
|
2004-08-21 13:59:48 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-06-01 08:19:02 +00:00
|
|
|
if ( $type == CACHE_DB || ( $inputType == CACHE_ANYTHING && $cache === false ) ) {
|
|
|
|
|
if ( !array_key_exists( CACHE_DB, $wgCaches ) ) {
|
* Converted BagOStuff.php from the style of memcached-client.php to the standard MediaWiki style, including camel case, using protected visibility instead of initial underscore, abstract functions instead of stubs, stylize.php.
* In SqlBagOStuff, ignore errors due to a read-only database, per my comments on CR r42796. Same for LocalisationCache.
* Merged SqlBagOStuff and MediaWikiBagOStuff, that proved to be an awkward and unnecessary generalisation. Use the standard quoting wrapper functions instead of $db->query().
* Implemented atomic incr() and decr() functions for SqlBagOStuff.
* Made incr() and decr() generally work roughly the same as it does in memcached, respecting negative steps instead of ignoring such operations. This allows decr() to be implemented in terms of incr().
* Per bug 11533, in MessageCache.php, don't retry 20 times on a cache failure, that's really memcached-specific and won't be useful for other cache types. It's not really very useful for memcached either.
* Moved MySQL-specific implementations of wasDeadlock() and wasErrorReissuable() to DatabaseMysql.
* Briefly tested page views with $wgReadOnly=read_only=1, fixed an error from Article::viewUpdates(). A CentralAuth fix will be in a subsequent commit.
2009-08-15 03:45:19 +00:00
|
|
|
$wgCaches[CACHE_DB] = new SqlBagOStuff('objectcache');
|
2006-06-01 08:19:02 +00:00
|
|
|
}
|
|
|
|
|
$cache =& $wgCaches[CACHE_DB];
|
2006-06-01 07:22:49 +00:00
|
|
|
}
|
2006-06-01 08:19:02 +00:00
|
|
|
|
|
|
|
|
if ( $cache === false ) {
|
|
|
|
|
if ( !array_key_exists( CACHE_NONE, $wgCaches ) ) {
|
|
|
|
|
$wgCaches[CACHE_NONE] = new FakeMemCachedClient;
|
|
|
|
|
}
|
|
|
|
|
$cache =& $wgCaches[CACHE_NONE];
|
2006-06-01 07:22:49 +00:00
|
|
|
}
|
2006-06-01 08:19:02 +00:00
|
|
|
|
|
|
|
|
return $cache;
|
2005-04-09 10:30:45 +00:00
|
|
|
}
|
2005-03-02 01:54:05 +00:00
|
|
|
|
2008-11-14 22:45:32 +00:00
|
|
|
/** Get the main cache object */
|
2006-06-01 08:19:02 +00:00
|
|
|
function &wfGetMainCache() {
|
|
|
|
|
global $wgMainCacheType;
|
|
|
|
|
$ret =& wfGetCache( $wgMainCacheType );
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-14 22:45:32 +00:00
|
|
|
/** Get the cache object used by the message cache */
|
2006-06-01 08:19:02 +00:00
|
|
|
function &wfGetMessageCacheStorage() {
|
|
|
|
|
global $wgMessageCacheType;
|
|
|
|
|
$ret =& wfGetCache( $wgMessageCacheType );
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-14 22:45:32 +00:00
|
|
|
/** Get the cache object used by the parser cache */
|
2006-06-01 08:19:02 +00:00
|
|
|
function &wfGetParserCacheStorage() {
|
|
|
|
|
global $wgParserCacheType;
|
|
|
|
|
$ret =& wfGetCache( $wgParserCacheType );
|
|
|
|
|
return $ret;
|
2005-04-09 10:30:45 +00:00
|
|
|
}
|