Parser cache respects $wgCacheEpoch
[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 $value = $wgMemc->get( $key );
22 if ( $value ) {
23 # Delete if article has changed since the cache was made
24 $touched = $article->getTouched();
25 if ( $value->getTouched() != $touched || $touched > $wgCacheEpoch ) {
26 $wgMemc->delete( $key );
27 $value = false;
28 }
29 } else {
30 $value = false;
31 }
32
33 wfProfileOut( $fname );
34 return $value;
35 }
36
37 function save( $parserOutput, &$article, &$user ){
38 global $wgMemc;
39 $key = $this->getKey( $article, $user );
40 $parserOutput->setTouched( $article->getTouched() );
41 if( $parserOutput->containsOldMagic() ){
42 $expire = 3600; # 1 hour
43 } else {
44 $expire = 7*86400; # 7 days
45 }
46
47 $wgMemc->set( $key, $parserOutput, $expire );
48 }
49
50 }
51
52
53 ?>