MediaWiki  1.27.1
CacheTime.php
Go to the documentation of this file.
1 <?php
29 class CacheTime {
33  public $mUsedOptions;
34 
35  # Compatibility check
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 
90  public function updateCacheExpiry( $seconds ) {
91  $seconds = (int)$seconds;
92 
93  if ( $this->mCacheExpiry === null || $this->mCacheExpiry > $seconds ) {
94  $this->mCacheExpiry = $seconds;
95  }
96  }
97 
107  public function getCacheExpiry() {
109 
110  if ( $this->mCacheTime < 0 ) {
111  return 0;
112  } // old-style marker for "not cacheable"
113 
114  $expire = $this->mCacheExpiry;
115 
116  if ( $expire === null ) {
117  $expire = $wgParserCacheExpireTime;
118  } else {
119  $expire = min( $expire, $wgParserCacheExpireTime );
120  }
121 
122  if ( $expire <= 0 ) {
123  return 0; // not cacheable
124  } else {
125  return $expire;
126  }
127  }
128 
132  public function isCacheable() {
133  return $this->getCacheExpiry() > 0;
134  }
135 
144  public function expired( $touched ) {
146 
147  return !$this->isCacheable() // parser says it's uncacheable
148  || $this->getCacheTime() < $touched
149  || $this->getCacheTime() <= $wgCacheEpoch
150  || $this->getCacheTime() <
151  wfTimestamp( TS_MW, time() - $this->getCacheExpiry() ) // expiry period has passed
152  || !isset( $this->mVersion )
153  || version_compare( $this->mVersion, Parser::VERSION, "lt" );
154  }
155 
168  public function isDifferentRevision( $id ) {
169  $cached = $this->getCacheRevisionId();
170  return $cached !== null && $id !== $cached;
171  }
172 }
$wgParserCacheExpireTime
The expiry time for the parser cache, in seconds.
Parser cache specific expiry check.
Definition: CacheTime.php:29
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
getCacheRevisionId()
Definition: CacheTime.php:68
setCacheRevisionId($id)
Definition: CacheTime.php:76
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getCacheExpiry()
Returns the number of seconds after which this object should expire.
Definition: CacheTime.php:107
expired($touched)
Return true if this cached output object predates the global or per-article cache invalidation timest...
Definition: CacheTime.php:144
const VERSION
Update this version number when the ParserOutput format changes in an incompatible way...
Definition: Parser.php:73
getCacheTime()
Definition: CacheTime.php:50
updateCacheExpiry($seconds)
Sets the number of seconds after which this object should expire.
Definition: CacheTime.php:90
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
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
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...
isDifferentRevision($id)
Return true if this cached output object is for a different revision of the page. ...
Definition: CacheTime.php:168
$mCacheRevisionId
Definition: CacheTime.php:45
$wgCacheEpoch
Set this to current time to invalidate all prior cached pages.
setCacheTime($t)
setCacheTime() sets the timestamp expressing when the page has been rendered.
Definition: CacheTime.php:60
array bool $mUsedOptions
ParserOptions which have been taken into account to produce output or false if not available...
Definition: CacheTime.php:33