MediaWiki  1.30.0
CacheTime.php
Go to the documentation of this file.
1 <?php
29 class CacheTime {
33  public $mUsedOptions;
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 ) {
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 }
CacheTime\getCacheExpiry
getCacheExpiry()
Returns the number of seconds after which this object should expire.
Definition: CacheTime.php:110
CacheTime
Parser cache specific expiry check.
Definition: CacheTime.php:29
CacheTime\$mCacheTime
$mCacheTime
Definition: CacheTime.php:39
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:1759
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2040
CacheTime\$mVersion
$mVersion
Definition: CacheTime.php:36
CacheTime\getCacheRevisionId
getCacheRevisionId()
Definition: CacheTime.php:68
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:60
CacheTime\isDifferentRevision
isDifferentRevision( $id)
Return true if this cached output object is for a different revision of the page.
Definition: CacheTime.php:171
$wgParserCacheExpireTime
$wgParserCacheExpireTime
The expiry time for the parser cache, in seconds.
Definition: DefaultSettings.php:2405
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
CacheTime\$mCacheExpiry
$mCacheExpiry
Definition: CacheTime.php:42
CacheTime\$mCacheRevisionId
$mCacheRevisionId
Definition: CacheTime.php:45
$wgCacheEpoch
$wgCacheEpoch
Set this to current time to invalidate all prior cached pages.
Definition: DefaultSettings.php:2532
CacheTime\expired
expired( $touched)
Return true if this cached output object predates the global or per-article cache invalidation timest...
Definition: CacheTime.php:147
CacheTime\setCacheRevisionId
setCacheRevisionId( $id)
Definition: CacheTime.php:76
CacheTime\updateCacheExpiry
updateCacheExpiry( $seconds)
Sets the number of seconds after which this object should expire.
Definition: CacheTime.php:93
CacheTime\isCacheable
isCacheable()
Definition: CacheTime.php:135
$t
$t
Definition: testCompression.php:67
CacheTime\getCacheTime
getCacheTime()
Definition: CacheTime.php:50
CacheTime\$mUsedOptions
array bool $mUsedOptions
ParserOptions which have been taken into account to produce output or false if not available.
Definition: CacheTime.php:33
array
the array() calling protocol came about after MediaWiki 1.4rc1.