Save a tag into the cached text indicating the key and the timestamp
[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 $touched = $article->getTouched();
41 $parserOutput->setTouched( $touched );
42 $parserOutput->mText .= "\n<-- Saved in parser cache with key $key and timestamp $touched -->\n";
43
44 if( $parserOutput->containsOldMagic() ){
45 $expire = 3600; # 1 hour
46 } else {
47 $expire = 7*86400; # 7 days
48 }
49
50 $wgMemc->set( $key, $parserOutput, $expire );
51 }
52
53 }
54
55
56 ?>