attempt to fix ini_set error by using set_include_path Patch by robertoz
[mediawiki.git] / includes / ParserCache.php
blobb6f5345a4af7394a9a7b4568e4212b9cf4ab83b9
1 <?php
2 /**
4 * @package MediaWiki
5 * @subpackage Cache
6 */
8 /**
10 * @package MediaWiki
12 class ParserCache {
13 /**
14 * Setup a cache pathway with a given back-end storage mechanism.
15 * May be a memcached client or a BagOStuff derivative.
17 * @param object $memCached
19 function ParserCache( &$memCached ) {
20 $this->mMemc =& $memCached;
23 function getKey( &$article, &$user ) {
24 global $wgDBname, $action;
25 $hash = $user->getPageRenderingHash();
26 $pageid = intval( $article->getID() );
27 $renderkey = (int)($action == 'render');
28 $key = "$wgDBname:pcache:idhash:$pageid-$renderkey!$hash";
29 return $key;
32 function getETag( &$article, &$user ) {
33 return 'W/"' . $this->getKey($article, $user) . "--" . $article->mTouched. '"';
36 function get( &$article, &$user ) {
37 global $wgCacheEpoch;
38 $fname = 'ParserCache::get';
39 wfProfileIn( $fname );
41 $hash = $user->getPageRenderingHash();
42 $pageid = intval( $article->getID() );
43 $key = $this->getKey( $article, $user );
45 wfDebug( "Trying parser cache $key\n" );
46 $value = $this->mMemc->get( $key );
47 if ( is_object( $value ) ) {
48 wfDebug( "Found.\n" );
49 # Delete if article has changed since the cache was made
50 $canCache = $article->checkTouched();
51 $cacheTime = $value->getCacheTime();
52 $touched = $article->mTouched;
53 if ( !$canCache || $value->expired( $touched ) ) {
54 if ( !$canCache ) {
55 wfIncrStats( "pcache_miss_invalid" );
56 wfDebug( "Invalid cached redirect, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
57 } else {
58 wfIncrStats( "pcache_miss_expired" );
59 wfDebug( "Key expired, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
61 $this->mMemc->delete( $key );
62 $value = false;
64 } else {
65 wfIncrStats( "pcache_hit" );
67 } else {
68 wfDebug( "Parser cache miss.\n" );
69 wfIncrStats( "pcache_miss_absent" );
70 $value = false;
73 wfProfileOut( $fname );
74 return $value;
77 function save( $parserOutput, &$article, &$user ){
78 $key = $this->getKey( $article, $user );
79 $now = wfTimestampNow();
80 $parserOutput->setCacheTime( $now );
81 $parserOutput->mText .= "\n<!-- Saved in parser cache with key $key and timestamp $now -->\n";
82 wfDebug( "Saved in parser cache with key $key and timestamp $now\n" );
84 if( $parserOutput->containsOldMagic() ){
85 $expire = 3600; # 1 hour
86 } else {
87 $expire = 86400; # 1 day
89 $this->mMemc->set( $key, $parserOutput, $expire );