MediaWiki REL1_31
CacheTime.php
Go to the documentation of this file.
1<?php
29class CacheTime {
34
35 # Compatibility check
36 public $mVersion = Parser::VERSION;
37
38 # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
39 public $mCacheTime = '';
40
41 # Seconds after which the object should expire, use 0 for uncacheable. Used in ParserCache.
42 public $mCacheExpiry = null;
43
44 # Revision ID that was parsed
45 public $mCacheRevisionId = null;
46
50 public function getCacheTime() {
51 return wfTimestamp( TS_MW, $this->mCacheTime );
52 }
53
60 public function setCacheTime( $t ) {
61 return wfSetVar( $this->mCacheTime, $t );
62 }
63
68 public function getCacheRevisionId() {
70 }
71
76 public function setCacheRevisionId( $id ) {
77 $this->mCacheRevisionId = $id;
78 }
79
93 public function updateCacheExpiry( $seconds ) {
94 $seconds = (int)$seconds;
95
96 if ( $this->mCacheExpiry === null || $this->mCacheExpiry > $seconds ) {
97 $this->mCacheExpiry = $seconds;
98 }
99 }
100
110 public function getCacheExpiry() {
112
113 if ( $this->mCacheTime < 0 ) {
114 return 0;
115 } // old-style marker for "not cacheable"
116
117 $expire = $this->mCacheExpiry;
118
119 if ( $expire === null ) {
120 $expire = $wgParserCacheExpireTime;
121 } else {
122 $expire = min( $expire, $wgParserCacheExpireTime );
123 }
124
125 if ( $expire <= 0 ) {
126 return 0; // not cacheable
127 } else {
128 return $expire;
129 }
130 }
131
135 public function isCacheable() {
136 return $this->getCacheExpiry() > 0;
137 }
138
147 public function expired( $touched ) {
148 global $wgCacheEpoch;
149
150 return !$this->isCacheable() // parser says it's uncacheable
151 || $this->getCacheTime() < $touched
152 || $this->getCacheTime() <= $wgCacheEpoch
153 || $this->getCacheTime() <
154 wfTimestamp( TS_MW, time() - $this->getCacheExpiry() ) // expiry period has passed
155 || !isset( $this->mVersion )
156 || version_compare( $this->mVersion, Parser::VERSION, "lt" );
157 }
158
171 public function isDifferentRevision( $id ) {
172 $cached = $this->getCacheRevisionId();
173 return $cached !== null && $id !== $cached;
174 }
175}
$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...
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Parser cache specific expiry check.
Definition CacheTime.php:29
getCacheRevisionId()
Definition CacheTime.php:68
setCacheRevisionId( $id)
Definition CacheTime.php:76
updateCacheExpiry( $seconds)
Sets the number of seconds after which this object should expire.
Definition CacheTime.php:93
array bool $mUsedOptions
ParserOptions which have been taken into account to produce output or false if not available.
Definition CacheTime.php:33
setCacheTime( $t)
setCacheTime() sets the timestamp expressing when the page has been rendered.
Definition CacheTime.php:60
isDifferentRevision( $id)
Return true if this cached output object is for a different revision of the page.
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.