MediaWiki  1.33.0
CacheTime.php
Go to the documentation of this file.
1 <?php
29 class CacheTime {
33  public $mUsedOptions;
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 }
CacheTime\getCacheExpiry
getCacheExpiry()
Returns the number of seconds after which this object should expire.
Definition: CacheTime.php:129
CacheTime
Parser cache specific expiry check.
Definition: CacheTime.php:29
wfSetVar
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...
Definition: GlobalFunctions.php:1633
CacheTime\$mCacheRevisionId
int null $mCacheRevisionId
Revision ID that was parsed.
Definition: CacheTime.php:55
CacheTime\getCacheRevisionId
getCacheRevisionId()
Definition: CacheTime.php:87
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
CacheTime\setCacheTime
setCacheTime( $t)
setCacheTime() sets the timestamp expressing when the page has been rendered.
Definition: CacheTime.php:74
CacheTime\isDifferentRevision
isDifferentRevision( $id)
Return true if this cached output object is for a different revision of the page.
Definition: CacheTime.php:192
$wgParserCacheExpireTime
$wgParserCacheExpireTime
The expiry time for the parser cache, in seconds.
Definition: DefaultSettings.php:2491
CacheTime\$mCacheExpiry
int null $mCacheExpiry
Seconds after which the object should expire, use 0 for not cacheable.
Definition: CacheTime.php:50
CacheTime\$mCacheTime
string int $mCacheTime
TS_MW timestamp when this object was generated, or -1 for not cacheable.
Definition: CacheTime.php:44
$wgCacheEpoch
$wgCacheEpoch
Set this to current time to invalidate all prior cached pages.
Definition: DefaultSettings.php:2608
CacheTime\expired
expired( $touched)
Return true if this cached output object predates the global or per-article cache invalidation timest...
Definition: CacheTime.php:167
CacheTime\setCacheRevisionId
setCacheRevisionId( $id)
Definition: CacheTime.php:95
CacheTime\updateCacheExpiry
updateCacheExpiry( $seconds)
Sets the number of seconds after which this object should expire.
Definition: CacheTime.php:112
CacheTime\isCacheable
isCacheable()
Definition: CacheTime.php:155
CacheTime\$mVersion
string null $mVersion
Compatibility check.
Definition: CacheTime.php:38
$t
$t
Definition: testCompression.php:69
CacheTime\$mUsedOptions
string[] $mUsedOptions
ParserOptions which have been taken into account to produce output.
Definition: CacheTime.php:33
CacheTime\getCacheTime
getCacheTime()
Definition: CacheTime.php:60