5 function getKey( &$article, &$user ) {
7 $hash = $user->getPageRenderingHash();
8 $pageid = intval( $article->getID() );
9 $key = "$wgDBname:pcache:idhash:$pageid-$hash";
13 function get( &$article, &$user ) {
14 global $wgMemc, $wgCacheEpoch;
15 $fname = "ParserCache::get";
16 wfProfileIn( $fname );
18 $hash = $user->getPageRenderingHash();
19 $pageid = intval( $article->getID() );
20 $key = $this->getKey( $article, $user );
21 wfDebug( "Trying parser cache $key\n" );
22 $value = $wgMemc->get( $key );
24 wfDebug( "Found.\n" );
25 # Delete if article has changed since the cache was made
26 $canCache = $article->checkTouched();
27 $cacheTime = $value->getCacheTime();
28 $touched = $article->mTouched
;
29 if ( !$canCache ||
$value->getCacheTime() <= $touched ||
$cacheTime < $wgCacheEpoch ) {
31 wfDebug( "Invalid cached redirect, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
33 wfDebug( "Key expired, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
35 $wgMemc->delete( $key );
42 wfProfileOut( $fname );
46 function save( $parserOutput, &$article, &$user ){
49 $key = $this->getKey( $article, $user );
50 $now = wfTimestampNow();
51 $parserOutput->setCacheTime( $now );
52 $parserOutput->mText
.= "\n<!-- Saved in parser cache with key $key and timestamp $now -->\n";
54 if( $parserOutput->containsOldMagic() ){
55 $expire = 3600; # 1 hour
57 $expire = 86400; # 1 day
60 $wgMemc->set( $key, $parserOutput, $expire );