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}}
41 * @return string TS_MW timestamp
43 function getCacheTime() {
44 return wfTimestamp( TS_MW
, $this->mCacheTime
);
50 function containsOldMagic() {
51 return $this->mContainsOldMagic
;
58 function setContainsOldMagic( $com ) {
59 return wfSetVar( $this->mContainsOldMagic
, $com );
63 * setCacheTime() sets the timestamp expressing when the page has been rendered.
64 * This does not control expiry, see updateCacheExpiry() for that!
68 function setCacheTime( $t ) {
69 return wfSetVar( $this->mCacheTime
, $t );
73 * Sets the number of seconds after which this object should expire.
74 * This value is used with the ParserCache.
75 * If called with a value greater than the value provided at any previous call,
76 * the new call has no effect. The value returned by getCacheExpiry is smaller
77 * or equal to the smallest number that was provided as an argument to
78 * updateCacheExpiry().
80 * @param $seconds number
82 function updateCacheExpiry( $seconds ) {
83 $seconds = (int)$seconds;
85 if ( $this->mCacheExpiry
=== null ||
$this->mCacheExpiry
> $seconds ) {
86 $this->mCacheExpiry
= $seconds;
89 // hack: set old-style marker for uncacheable entries.
90 if ( $this->mCacheExpiry
!== null && $this->mCacheExpiry
<= 0 ) {
91 $this->mCacheTime
= -1;
96 * Returns the number of seconds after which this object should expire.
97 * This method is used by ParserCache to determine how long the ParserOutput can be cached.
98 * The timestamp of expiry can be calculated by adding getCacheExpiry() to getCacheTime().
99 * The value returned by getCacheExpiry is smaller or equal to the smallest number
100 * that was provided to a call of updateCacheExpiry(), and smaller or equal to the
101 * value of $wgParserCacheExpireTime.
102 * @return int|mixed|null
104 function getCacheExpiry() {
105 global $wgParserCacheExpireTime;
107 if ( $this->mCacheTime
< 0 ) {
109 } // old-style marker for "not cachable"
111 $expire = $this->mCacheExpiry
;
113 if ( $expire === null ) {
114 $expire = $wgParserCacheExpireTime;
116 $expire = min( $expire, $wgParserCacheExpireTime );
119 if ( $this->containsOldMagic() ) { //compatibility hack
120 $expire = min( $expire, 3600 ); # 1 hour
123 if ( $expire <= 0 ) {
124 return 0; // not cachable
133 function isCacheable() {
134 return $this->getCacheExpiry() > 0;
138 * Return true if this cached output object predates the global or
139 * per-article cache invalidation timestamps, or if it comes from
140 * an incompatible older version.
142 * @param string $touched the affected article's last touched timestamp
145 public function expired( $touched ) {
146 global $wgCacheEpoch;
147 return !$this->isCacheable() ||
// parser says it's uncacheable
148 $this->getCacheTime() < $touched ||
149 $this->getCacheTime() <= $wgCacheEpoch ||
150 $this->getCacheTime() < wfTimestamp( TS_MW
, time() - $this->getCacheExpiry() ) ||
// expiry period has passed
151 !isset( $this->mVersion
) ||
152 version_compare( $this->mVersion
, Parser
::VERSION
, "lt" );