Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -4787,7 +4787,8 @@ |
4788 | 4788 | */ |
4789 | 4789 | function disableCache() { |
4790 | 4790 | wfDebug( "Parser output marked as uncacheable.\n" ); |
4791 | | - $this->mOutput->mCacheTime = -1; |
| 4791 | + $this->mOutput->setCacheTime( -1 ); // old style, for compatibility |
| 4792 | + $this->mOutput->setCacheExpiry( 0 ); // new style, for consistency |
4792 | 4793 | } |
4793 | 4794 | |
4794 | 4795 | /**#@+ |
Index: trunk/phase3/includes/parser/ParserOutput.php |
— | — | @@ -11,6 +11,7 @@ |
12 | 12 | $mContainsOldMagic, # Boolean variable indicating if the input contained variables like {{CURRENTDAY}} |
13 | 13 | $mTitleText, # title text of the chosen language variant |
14 | 14 | $mCacheTime = '', # Time when this object was generated, or -1 for uncacheable. Used in ParserCache. |
| 15 | + $mCacheExpiry = null, # Seconds after which the object should expire, use 0 for uncachable. Used in ParserCache. |
15 | 16 | $mVersion = Parser::VERSION, # Compatibility check |
16 | 17 | $mLinks = array(), # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken. |
17 | 18 | $mTemplates = array(), # 2-D map of NS/DBK to ID for the template references. ID=zero for broken. |
— | — | @@ -64,12 +65,66 @@ |
65 | 66 | function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); } |
66 | 67 | function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); } |
67 | 68 | function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); } |
68 | | - function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); } |
| 69 | + |
| 70 | + /** setCacheTime() sets the timestamp expressing when the page has been rendered. |
| 71 | + * This doesn not control expiry, see updateCacheExpiry() for that! |
| 72 | + */ |
| 73 | + function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); } |
69 | 74 | function setTitleText( $t ) { return wfSetVar( $this->mTitleText, $t ); } |
70 | 75 | function setSections( $toc ) { return wfSetVar( $this->mSections, $toc ); } |
71 | 76 | function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy, $policy ); } |
72 | 77 | function setTOCHTML( $tochtml ) { return wfSetVar( $this->mTOCHTML, $tochtml ); } |
73 | 78 | |
| 79 | + |
| 80 | + /** Sets the number of seconds after which this object should expire. |
| 81 | + * This value is used with the ParserCache. |
| 82 | + * If called with a value greater than the value provided at any previous call, |
| 83 | + * the new call has no effect. The value returned by getCacheExpiry is smaller |
| 84 | + * or equal to the smallest number that was provided as an argument to |
| 85 | + * updateCacheExpiry(). |
| 86 | + */ |
| 87 | + function updateCacheExpiry( $seconds ) { |
| 88 | + $seconds = (int)$seconds; |
| 89 | + |
| 90 | + if ( $this->mCacheExpiry === null || $this->mCacheExpiry > $seconds ) |
| 91 | + $this->mCacheExpiry = $seconds; |
| 92 | + |
| 93 | + // hack: set old-style marker for uncacheable entries. |
| 94 | + if ( $this->mCacheExpiry !== null && $this->mCacheExpiry <= 0 ) |
| 95 | + $this->mCacheTime = -1; |
| 96 | + } |
| 97 | + |
| 98 | + /** Returns the number of seconds after which this object should expire. |
| 99 | + * This method is used by ParserCache to determine how long the ParserOutput can be cached. |
| 100 | + * The timestamp of expiry can be calculated by adding getCacheExpiry() to getCacheTime(). |
| 101 | + * The value returned by getCacheExpiry is smaller or equal to the smallest number |
| 102 | + * that was provided to a call of updateCacheExpiry(), and smaller or equal to the |
| 103 | + * value of $wgParserCacheExpireTime. |
| 104 | + */ |
| 105 | + function getCacheExpiry() { |
| 106 | + global $wgParserCacheExpireTime; |
| 107 | + |
| 108 | + if ( $this->mCacheTime < 0 ) return 0; // old-style marker for "not cachable" |
| 109 | + |
| 110 | + $expire = $this->mCacheExpiry; |
| 111 | + |
| 112 | + if ( $expire === null ) |
| 113 | + $expire = $wgParserCacheExpireTime; |
| 114 | + else |
| 115 | + $expire = min( $expire, $wgParserCacheExpireTime ); |
| 116 | + |
| 117 | + if( $this->containsOldMagic() ) { //compatibility hack |
| 118 | + $expire = min( $expire, 3600 ); # 1 hour |
| 119 | + } |
| 120 | + |
| 121 | + if ( $expire <= 0 ) return 0; // not cachable |
| 122 | + else return $expire; |
| 123 | + } |
| 124 | + |
| 125 | + function isCacheable() { |
| 126 | + return $this->getCacheExpiry() > 0; |
| 127 | + } |
| 128 | + |
74 | 129 | function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; } |
75 | 130 | function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; } |
76 | 131 | function addWarning( $s ) { $this->mWarnings[$s] = 1; } |
— | — | @@ -174,9 +229,10 @@ |
175 | 230 | */ |
176 | 231 | public function expired( $touched ) { |
177 | 232 | global $wgCacheEpoch; |
178 | | - return $this->getCacheTime() == -1 || // parser says it's uncacheable |
| 233 | + return !$this->isCacheable() || // parser says it's uncacheable |
179 | 234 | $this->getCacheTime() < $touched || |
180 | 235 | $this->getCacheTime() <= $wgCacheEpoch || |
| 236 | + $this->getCacheTime() < wfTimestamp( TS_MW, time() - $this->getCacheExpiry() ) || // expiry period has passed |
181 | 237 | !isset( $this->mVersion ) || |
182 | 238 | version_compare( $this->mVersion, Parser::VERSION, "lt" ); |
183 | 239 | } |
Index: trunk/phase3/includes/parser/ParserCache.php |
— | — | @@ -96,11 +96,10 @@ |
97 | 97 | } |
98 | 98 | |
99 | 99 | function save( $parserOutput, $article, $popts ){ |
100 | | - global $wgParserCacheExpireTime; |
101 | 100 | $key = $this->getKey( $article, $popts ); |
| 101 | + $expire = $parserOutput->getCacheExpiry(); |
102 | 102 | |
103 | | - if( $parserOutput->getCacheTime() != -1 ) { |
104 | | - |
| 103 | + if( $expire > 0 ) { |
105 | 104 | $now = wfTimestampNow(); |
106 | 105 | $parserOutput->setCacheTime( $now ); |
107 | 106 | |
— | — | @@ -110,11 +109,6 @@ |
111 | 110 | $parserOutput->mText .= "\n<!-- Saved in parser cache with key $key and timestamp $now -->\n"; |
112 | 111 | wfDebug( "Saved in parser cache with key $key and timestamp $now\n" ); |
113 | 112 | |
114 | | - if( $parserOutput->containsOldMagic() ){ |
115 | | - $expire = 3600; # 1 hour |
116 | | - } else { |
117 | | - $expire = $wgParserCacheExpireTime; |
118 | | - } |
119 | 113 | $this->mMemc->set( $key, $parserOutput, $expire ); |
120 | 114 | |
121 | 115 | } else { |
Index: trunk/phase3/includes/Article.php |
— | — | @@ -4457,7 +4457,7 @@ |
4458 | 4458 | $this->mTitle->getPrefixedDBkey() ) ); |
4459 | 4459 | } |
4460 | 4460 | |
4461 | | - if ( $wgEnableParserCache && $cache && $this && $this->mParserOutput->getCacheTime() != -1 ) { |
| 4461 | + if ( $wgEnableParserCache && $cache && $this && !$this->mParserOutput->isCacheable() ) { |
4462 | 4462 | $parserCache = ParserCache::singleton(); |
4463 | 4463 | $parserCache->save( $this->mParserOutput, $this, $parserOptions ); |
4464 | 4464 | } |
— | — | @@ -4465,7 +4465,7 @@ |
4466 | 4466 | // Make sure file cache is not used on uncacheable content. |
4467 | 4467 | // Output that has magic words in it can still use the parser cache |
4468 | 4468 | // (if enabled), though it will generally expire sooner. |
4469 | | - if ( $this->mParserOutput->getCacheTime() == -1 || $this->mParserOutput->containsOldMagic() ) { |
| 4469 | + if ( !$this->mParserOutput->isCacheable() || $this->mParserOutput->containsOldMagic() ) { |
4470 | 4470 | $wgUseFileCache = false; |
4471 | 4471 | } |
4472 | 4472 | |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -1050,7 +1050,7 @@ |
1051 | 1051 | $popts, true, true, $this->mRevisionId |
1052 | 1052 | ); |
1053 | 1053 | $popts->setTidy( false ); |
1054 | | - if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) { |
| 1054 | + if ( $cache && $article && !$parserOutput->isCacheable() ) { |
1055 | 1055 | $parserCache = ParserCache::singleton(); |
1056 | 1056 | $parserCache->save( $parserOutput, $article, $popts ); |
1057 | 1057 | } |
— | — | @@ -1078,7 +1078,7 @@ |
1079 | 1079 | $this->mHideNewSectionLink = $parserOutput->getHideNewSection(); |
1080 | 1080 | |
1081 | 1081 | $this->mParseWarnings = $parserOutput->getWarnings(); |
1082 | | - if ( $parserOutput->getCacheTime() == -1 ) { |
| 1082 | + if ( !$parserOutput->isCacheable() ) { |
1083 | 1083 | $this->enableClientCache( false ); |
1084 | 1084 | } |
1085 | 1085 | $this->mNoGallery = $parserOutput->getNoGallery(); |