Experimental authentication plugin interface. Will require a little bit more work...
[mediawiki.git] / includes / ParserCache.php
blobed4384dbbdb32c2f5b7bed053224afdc514f69b3
1 <?php
2 /**
4 * @package MediaWiki
5 */
7 /**
9 * @package MediaWiki
11 class ParserCache
13 function getKey( &$article, &$user ) {
14 global $wgDBname;
15 $hash = $user->getPageRenderingHash();
16 $pageid = intval( $article->getID() );
17 $key = "$wgDBname:pcache:idhash:$pageid-$hash";
18 return $key;
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 ) {
38 if ( !$canCache ) {
39 wfDebug( "Invalid cached redirect, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
40 } else {
41 wfDebug( "Key expired, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
43 $wgMemc->delete( $key );
44 $value = false;
46 } else {
47 wfDebug( "Parser cache miss.\n" );
48 $value = false;
51 wfProfileOut( $fname );
52 return $value;
55 function save( $parserOutput, &$article, &$user ){
56 global $wgMemc;
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
65 } else {
66 $expire = 86400; # 1 day
69 $wgMemc->set( $key, $parserOutput, $expire );