11 function getKey( &$article, &$user ) {
13 $hash = $user->getPageRenderingHash();
14 $pageid = intval( $article->getID() );
15 $key = "$wgDBname:pcache:idhash:$pageid-$hash";
19 function get( &$article, &$user ) {
20 global $wgMemc, $wgCacheEpoch;
21 $fname = 'ParserCache::get';
22 wfProfileIn( $fname );
24 $hash = $user->getPageRenderingHash();
25 $pageid = intval( $article->getID() );
26 $key = $this->getKey( $article, $user );
27 wfDebug( "Trying parser cache $key\n" );
28 $value = $wgMemc->get( $key );
30 wfDebug( "Found.\n" );
31 # Delete if article has changed since the cache was made
32 $canCache = $article->checkTouched();
33 $cacheTime = $value->getCacheTime();
34 $touched = $article->mTouched
;
35 if ( !$canCache ||
$value->getCacheTime() <= $touched ||
$cacheTime < $wgCacheEpoch ) {
37 wfDebug( "Invalid cached redirect, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
39 wfDebug( "Key expired, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
41 $wgMemc->delete( $key );
48 wfProfileOut( $fname );
52 function save( $parserOutput, &$article, &$user ){
55 $key = $this->getKey( $article, $user );
56 $now = wfTimestampNow();
57 $parserOutput->setCacheTime( $now );
58 $parserOutput->mText
.= "\n<!-- Saved in parser cache with key $key and timestamp $now -->\n";
60 if( $parserOutput->containsOldMagic() ){
61 $expire = 3600; # 1 hour
63 $expire = 86400; # 1 day
66 $wgMemc->set( $key, $parserOutput, $expire );