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