Parser cache moved to memcached
[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;
15 $hash = $user->getPageRenderingHash();
16 $pageid = intval( $article->getID() );
17 $key = $this->getKey( $article, $user );
18 $value = $wgMemc->get( $key );
19 if ( $value ) {
20 # Delete if article has changed since the cache was made
21 if ( $value->getTouched() != $article->getTouched() ) {
22 $wgMemc->delete( $key );
23 $value = false;
24 }
25 } else {
26 $value = false;
27 }
28 return $value;
29 }
30
31 function save( $parserOutput, &$article, &$user ){
32 global $wgMemc;
33 $key = $this->getKey( $article, $user );
34 $parserOutput->setTouched( $article->getTouched() );
35 if( $parserOutput->containsOldMagic() ){
36 $expire = 3600; # 1 hour
37 } else {
38 $expire = 7*86400; # 7 days
39 }
40
41 $wgMemc->set( $key, $parserOutput, $expire );
42 }
43
44 }
45
46
47 ?>