RC patrol fixlet: include rcid in 'diff' link in enhanced mode, for individually...
[mediawiki.git] / includes / ParserCache.php
blob00ed003058538c16d91ae0da23bc52b21fe68dc5
1 <?php
2 /**
4 * @package MediaWiki
5 */
7 /**
9 * @package MediaWiki
11 class ParserCache {
12 /**
13 * Setup a cache pathway with a given back-end storage mechanism.
14 * May be a memcached client or a BagOStuff derivative.
16 * @param object $memCached
18 function ParserCache( &$memCached ) {
19 $this->mMemc =& $memCached;
22 function getKey( &$article, &$user ) {
23 global $wgDBname;
24 $hash = $user->getPageRenderingHash();
25 $pageid = intval( $article->getID() );
26 $key = "$wgDBname:pcache:idhash:$pageid-$hash";
27 return $key;
30 function get( &$article, &$user ) {
31 global $wgCacheEpoch;
32 $fname = 'ParserCache::get';
33 wfProfileIn( $fname );
35 $hash = $user->getPageRenderingHash();
36 $pageid = intval( $article->getID() );
37 $key = $this->getKey( $article, $user );
38 wfDebug( "Trying parser cache $key\n" );
39 $value = $this->mMemc->get( $key );
40 if ( is_object( $value ) ) {
41 wfDebug( "Found.\n" );
42 # Delete if article has changed since the cache was made
43 $canCache = $article->checkTouched();
44 $cacheTime = $value->getCacheTime();
45 $touched = $article->mTouched;
46 if ( !$canCache || $value->expired( $touched ) ) {
47 if ( !$canCache ) {
48 wfDebug( "Invalid cached redirect, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
49 } else {
50 wfDebug( "Key expired, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
52 $this->mMemc->delete( $key );
53 $value = false;
55 } else {
56 wfDebug( "Parser cache miss.\n" );
57 $value = false;
60 wfProfileOut( $fname );
61 return $value;
64 function save( $parserOutput, &$article, &$user ){
65 $key = $this->getKey( $article, $user );
66 $now = wfTimestampNow();
67 $parserOutput->setCacheTime( $now );
68 $parserOutput->mText .= "\n<!-- Saved in parser cache with key $key and timestamp $now -->\n";
69 wfDebug( "Saved in parser cache with key $key and timestamp $now\n" );
71 if( $parserOutput->containsOldMagic() ){
72 $expire = 3600; # 1 hour
73 } else {
74 $expire = 86400; # 1 day
76 $this->mMemc->set( $key, $parserOutput, $expire );