MediaWiki  master
CacheTime.php
Go to the documentation of this file.
1 <?php
29 class CacheTime {
33  public $mUsedOptions;
34 
39 
44  public $mCacheTime = '';
45 
50  public $mCacheExpiry = null;
51 
55  public $mCacheRevisionId = null;
56 
60  public function getCacheTime() {
61  // NOTE: keep support for undocumented used of -1 to mean "not cacheable".
62  if ( $this->mCacheTime === '' ) {
63  $this->mCacheTime = MWTimestamp::now();
64  }
65  return $this->mCacheTime;
66  }
67 
74  public function setCacheTime( $t ) {
75  // NOTE: keep support for undocumented used of -1 to mean "not cacheable".
76  if ( is_string( $t ) && $t !== '-1' ) {
77  $t = MWTimestamp::convert( TS_MW, $t );
78  }
79 
80  return wfSetVar( $this->mCacheTime, $t );
81  }
82 
87  public function getCacheRevisionId() {
89  }
90 
95  public function setCacheRevisionId( $id ) {
96  $this->mCacheRevisionId = $id;
97  }
98 
112  public function updateCacheExpiry( $seconds ) {
113  $seconds = (int)$seconds;
114 
115  if ( $this->mCacheExpiry === null || $this->mCacheExpiry > $seconds ) {
116  $this->mCacheExpiry = $seconds;
117  }
118  }
119 
129  public function getCacheExpiry() {
131 
132  // NOTE: keep support for undocumented used of -1 to mean "not cacheable".
133  if ( $this->mCacheTime < 0 ) {
134  return 0;
135  }
136 
137  $expire = $this->mCacheExpiry;
138 
139  if ( $expire === null ) {
140  $expire = $wgParserCacheExpireTime;
141  } else {
142  $expire = min( $expire, $wgParserCacheExpireTime );
143  }
144 
145  if ( $expire <= 0 ) {
146  return 0; // not cacheable
147  } else {
148  return $expire;
149  }
150  }
151 
155  public function isCacheable() {
156  return $this->getCacheExpiry() > 0;
157  }
158 
167  public function expired( $touched ) {
168  global $wgCacheEpoch;
169 
170  $expiry = MWTimestamp::convert( TS_MW, MWTimestamp::time() - $this->getCacheExpiry() );
171 
172  return !$this->isCacheable() // parser says it's not cacheable
173  || $this->getCacheTime() < $touched
174  || $this->getCacheTime() <= $wgCacheEpoch
175  || $this->getCacheTime() < $expiry // expiry period has passed
176  || !isset( $this->mVersion )
177  || version_compare( $this->mVersion, Parser::VERSION, "lt" );
178  }
179 
192  public function isDifferentRevision( $id ) {
193  $cached = $this->getCacheRevisionId();
194  return $cached !== null && $id !== $cached;
195  }
196 }
$wgParserCacheExpireTime
The expiry time for the parser cache, in seconds.
setCacheTime( $t)
setCacheTime() sets the timestamp expressing when the page has been rendered.
Definition: CacheTime.php:74
Parser cache specific expiry check.
Definition: CacheTime.php:29
getCacheRevisionId()
Definition: CacheTime.php:87
int null $mCacheRevisionId
Revision ID that was parsed.
Definition: CacheTime.php:55
int null $mCacheExpiry
Seconds after which the object should expire, use 0 for not cacheable.
Definition: CacheTime.php:50
string int $mCacheTime
TS_MW timestamp when this object was generated, or -1 for not cacheable.
Definition: CacheTime.php:44
getCacheExpiry()
Returns the number of seconds after which this object should expire.
Definition: CacheTime.php:129
expired( $touched)
Return true if this cached output object predates the global or per-article cache invalidation timest...
Definition: CacheTime.php:167
isDifferentRevision( $id)
Return true if this cached output object is for a different revision of the page. ...
Definition: CacheTime.php:192
const VERSION
Update this version number when the ParserOutput format changes in an incompatible way...
Definition: Parser.php:80
setCacheRevisionId( $id)
Definition: CacheTime.php:95
getCacheTime()
Definition: CacheTime.php:60
string null $mVersion
Compatibility check.
Definition: CacheTime.php:38
wfSetVar(&$dest, $source, $force=false)
Sets dest to source and returns the original value of dest If source is NULL, it just returns the val...
string [] $mUsedOptions
ParserOptions which have been taken into account to produce output.
Definition: CacheTime.php:33
updateCacheExpiry( $seconds)
Sets the number of seconds after which this object should expire.
Definition: CacheTime.php:112
$wgCacheEpoch
Set this to current time to invalidate all prior cached pages.