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 );
31 if ( is_object( $value ) ) {
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 );
47 wfDebug( "Parser cache miss.\n" );
51 wfProfileOut( $fname );
55 function save( $parserOutput, &$article, &$user ){
58 $key = $this->getKey( $article, $user );
59 $now = wfTimestampNow();
60 $parserOutput->setCacheTime( $now );
61 $parserOutput->mText
.= "\n<!-- Saved in parser cache with key $key and timestamp $now -->\n";
63 if( $parserOutput->containsOldMagic() ){
64 $expire = 3600; # 1 hour
66 $expire = 86400; # 1 day
69 $wgMemc->set( $key, $parserOutput, $expire );