Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

ParserCache.php

Go to the documentation of this file.
00001 <?php 00002 00003 class ParserCache 00004 { 00005 function getKey( &$article, &$user ) { 00006 global $wgDBname; 00007 $hash = $user->getPageRenderingHash(); 00008 $pageid = intval( $article->getID() ); 00009 $key = "$wgDBname:pcache:idhash:$pageid-$hash"; 00010 return $key; 00011 } 00012 00013 function get( &$article, &$user ) { 00014 global $wgMemc, $wgCacheEpoch; 00015 $fname = "ParserCache::get"; 00016 wfProfileIn( $fname ); 00017 00018 $hash = $user->getPageRenderingHash(); 00019 $pageid = intval( $article->getID() ); 00020 $key = $this->getKey( $article, $user ); 00021 wfDebug( "Trying parser cache $key\n" ); 00022 $value = $wgMemc->get( $key ); 00023 if ( $value ) { 00024 wfDebug( "Found.\n" ); 00025 # Delete if article has changed since the cache was made 00026 $canCache = $article->checkTouched(); 00027 $cacheTime = $value->getCacheTime(); 00028 $touched = $article->mTouched; 00029 if ( !$canCache || $value->getCacheTime() <= $touched || $cacheTime < $wgCacheEpoch ) { 00030 if ( !$canCache ) { 00031 wfDebug( "Invalid cached redirect, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" ); 00032 } else { 00033 wfDebug( "Key expired, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" ); 00034 } 00035 $wgMemc->delete( $key ); 00036 $value = false; 00037 } 00038 } else { 00039 $value = false; 00040 } 00041 00042 wfProfileOut( $fname ); 00043 return $value; 00044 } 00045 00046 function save( $parserOutput, &$article, &$user ){ 00047 global $wgMemc; 00048 00049 $key = $this->getKey( $article, $user ); 00050 $now = wfTimestampNow(); 00051 $parserOutput->setCacheTime( $now ); 00052 $parserOutput->mText .= "\n<!-- Saved in parser cache with key $key and timestamp $now -->\n"; 00053 00054 if( $parserOutput->containsOldMagic() ){ 00055 $expire = 3600; # 1 hour 00056 } else { 00057 $expire = 86400; # 1 day 00058 } 00059 00060 $wgMemc->set( $key, $parserOutput, $expire ); 00061 } 00062 } 00063 00064 00065 ?>

Generated on Tue Jun 29 23:40:06 2004 for Mediawiki by doxygen 1.3.7