Extra debugging info and a typo fix
[lhc/web/wiklou.git] / includes / ParserCache.php
1 <?php
2
3 class ParserCache
4 {
5 function getKey( &$article, &$user ) {
6 global $wgDBname;
7 $hash = $user->getPageRenderingHash();
8 $pageid = intval( $article->getID() );
9 $key = "$wgDBname:pcache:idhash:$pageid-$hash";
10 return $key;
11 }
12
13 function get( &$article, &$user ) {
14 global $wgMemc, $wgCacheEpoch;
15 $fname = "ParserCache::get";
16 wfProfileIn( $fname );
17
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 );
23 if ( $value ) {
24 wfDebug( "Found.\n" );
25 # Delete if article has changed since the cache was made
26 $touched = $article->getTouched();
27 $cacheTime = $value->getCacheTime();
28 if ( $value->getCacheTime() <= $touched || $cacheTime < $wgCacheEpoch ) {
29 wfDebug( "Key expired, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
30 $wgMemc->delete( $key );
31 $value = false;
32 }
33 } else {
34 $value = false;
35 }
36
37 wfProfileOut( $fname );
38 return $value;
39 }
40
41 function save( $parserOutput, &$article, &$user ){
42 global $wgMemc;
43 $key = $this->getKey( $article, $user );
44 $now = wfTimestampNow();
45 $parserOutput->setCacheTime( $now );
46 $parserOutput->mText .= "\n<!-- Saved in parser cache with key $key and timestamp $now -->\n";
47
48 if( $parserOutput->containsOldMagic() ){
49 $expire = 3600; # 1 hour
50 } else {
51 $expire = 86400; # 1 day
52 }
53
54 $wgMemc->set( $key, $parserOutput, $expire );
55 }
56 }
57
58
59 ?>