3 * Parser cache specific expiry check.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * Parser cache specific expiry check.
30 /** @var array|bool ParserOptions which have been taken into account to
31 * produce output or false if not available.
35 var $mVersion = Parser
::VERSION
, # Compatibility check
36 $mCacheTime = '', # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
37 $mCacheExpiry = null, # Seconds after which the object should expire, use 0 for uncachable. Used in ParserCache.
38 $mContainsOldMagic; # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
40 function getCacheTime() { return $this->mCacheTime
; }
42 function containsOldMagic() { return $this->mContainsOldMagic
; }
43 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic
, $com ); }
46 * setCacheTime() sets the timestamp expressing when the page has been rendered.
47 * This doesn not control expiry, see updateCacheExpiry() for that!
51 function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime
, $t ); }
54 * Sets the number of seconds after which this object should expire.
55 * This value is used with the ParserCache.
56 * If called with a value greater than the value provided at any previous call,
57 * the new call has no effect. The value returned by getCacheExpiry is smaller
58 * or equal to the smallest number that was provided as an argument to
59 * updateCacheExpiry().
61 * @param $seconds number
63 function updateCacheExpiry( $seconds ) {
64 $seconds = (int)$seconds;
66 if ( $this->mCacheExpiry
=== null ||
$this->mCacheExpiry
> $seconds ) {
67 $this->mCacheExpiry
= $seconds;
70 // hack: set old-style marker for uncacheable entries.
71 if ( $this->mCacheExpiry
!== null && $this->mCacheExpiry
<= 0 ) {
72 $this->mCacheTime
= -1;
77 * Returns the number of seconds after which this object should expire.
78 * This method is used by ParserCache to determine how long the ParserOutput can be cached.
79 * The timestamp of expiry can be calculated by adding getCacheExpiry() to getCacheTime().
80 * The value returned by getCacheExpiry is smaller or equal to the smallest number
81 * that was provided to a call of updateCacheExpiry(), and smaller or equal to the
82 * value of $wgParserCacheExpireTime.
83 * @return int|mixed|null
85 function getCacheExpiry() {
86 global $wgParserCacheExpireTime;
88 if ( $this->mCacheTime
< 0 ) {
90 } // old-style marker for "not cachable"
92 $expire = $this->mCacheExpiry
;
94 if ( $expire === null ) {
95 $expire = $wgParserCacheExpireTime;
97 $expire = min( $expire, $wgParserCacheExpireTime );
100 if ( $this->containsOldMagic() ) { //compatibility hack
101 $expire = min( $expire, 3600 ); # 1 hour
104 if ( $expire <= 0 ) {
105 return 0; // not cachable
114 function isCacheable() {
115 return $this->getCacheExpiry() > 0;
119 * Return true if this cached output object predates the global or
120 * per-article cache invalidation timestamps, or if it comes from
121 * an incompatible older version.
123 * @param string $touched the affected article's last touched timestamp
126 public function expired( $touched ) {
127 global $wgCacheEpoch;
128 return !$this->isCacheable() ||
// parser says it's uncacheable
129 $this->getCacheTime() < $touched ||
130 $this->getCacheTime() <= $wgCacheEpoch ||
131 $this->getCacheTime() < wfTimestamp( TS_MW
, time() - $this->getCacheExpiry() ) ||
// expiry period has passed
132 !isset( $this->mVersion
) ||
133 version_compare( $this->mVersion
, Parser
::VERSION
, "lt" );