* @package MediaWiki
*/
class ParserCache {
+ /**
+ * Get an instance of this object
+ */
+ function &singleton() {
+ static $instance;
+ if ( !isset( $instance ) ) {
+ global $parserMemc;
+ $instance = new ParserCache( $parserMemc );
+ }
+ return $instance;
+ }
+
/**
* Setup a cache pathway with a given back-end storage mechanism.
* May be a memcached client or a BagOStuff derivative.
function ParserCache( &$memCached ) {
$this->mMemc =& $memCached;
}
-
+
function getKey( &$article, &$user ) {
- global $wgDBname;
+ global $wgDBname, $action;
$hash = $user->getPageRenderingHash();
+ if( !$article->mTitle->userCanEdit() ) {
+ // section edit links are suppressed even if the user has them on
+ $edit = '!edit=0';
+ } else {
+ $edit = '';
+ }
$pageid = intval( $article->getID() );
- $key = "$wgDBname:pcache:idhash:$pageid-$hash";
+ $renderkey = (int)($action == 'render');
+ $key = "$wgDBname:pcache:idhash:$pageid-$renderkey!$hash$edit";
return $key;
}
-
+
+ function getETag( &$article, &$user ) {
+ return 'W/"' . $this->getKey($article, $user) . "--" . $article->mTouched. '"';
+ }
+
function get( &$article, &$user ) {
global $wgCacheEpoch;
$fname = 'ParserCache::get';
wfProfileOut( $fname );
return $value;
}
-
+
function save( $parserOutput, &$article, &$user ){
+ global $wgParserCacheExpireTime;
$key = $this->getKey( $article, $user );
$now = wfTimestampNow();
$parserOutput->setCacheTime( $now );
if( $parserOutput->containsOldMagic() ){
$expire = 3600; # 1 hour
} else {
- $expire = 86400; # 1 day
+ $expire = $wgParserCacheExpireTime;
}
$this->mMemc->set( $key, $parserOutput, $expire );
}