MediaWiki REL1_34
CacheTime.php
Go to the documentation of this file.
1<?php
29class CacheTime {
34
38 public $mVersion = Parser::VERSION;
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}
$wgCacheEpoch
Set this to current time to invalidate all prior cached pages.
$wgParserCacheExpireTime
The expiry time for the parser cache, in seconds.
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...
Parser cache specific expiry check.
Definition CacheTime.php:29
int null $mCacheRevisionId
Revision ID that was parsed.
Definition CacheTime.php:55
string int $mCacheTime
TS_MW timestamp when this object was generated, or -1 for not cacheable.
Definition CacheTime.php:44
getCacheRevisionId()
Definition CacheTime.php:87
setCacheRevisionId( $id)
Definition CacheTime.php:95
string null $mVersion
Compatibility check.
Definition CacheTime.php:38
updateCacheExpiry( $seconds)
Sets the number of seconds after which this object should expire.
setCacheTime( $t)
setCacheTime() sets the timestamp expressing when the page has been rendered.
Definition CacheTime.php:74
isDifferentRevision( $id)
Return true if this cached output object is for a different revision of the page.
string[] $mUsedOptions
ParserOptions which have been taken into account to produce output.
Definition CacheTime.php:33
int null $mCacheExpiry
Seconds after which the object should expire, use 0 for not cacheable.
Definition CacheTime.php:50
expired( $touched)
Return true if this cached output object predates the global or per-article cache invalidation timest...
getCacheExpiry()
Returns the number of seconds after which this object should expire.