MediaWiki  REL1_23
CacheTime.php
Go to the documentation of this file.
00001 <?php
00029 class CacheTime {
00033     public $mUsedOptions;
00034 
00035     var $mVersion = Parser::VERSION,  # Compatibility check
00036         $mCacheTime = '',             # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
00037         $mCacheExpiry = null,         # Seconds after which the object should expire, use 0 for uncachable. Used in ParserCache.
00038         $mContainsOldMagic,           # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
00039         $mCacheRevisionId = null;     # Revision ID that was parsed
00040 
00044     function getCacheTime() {
00045         return wfTimestamp( TS_MW, $this->mCacheTime );
00046     }
00047 
00051     function containsOldMagic() {
00052         return $this->mContainsOldMagic;
00053     }
00054 
00059     function setContainsOldMagic( $com ) {
00060         return wfSetVar( $this->mContainsOldMagic, $com );
00061     }
00062 
00069     function setCacheTime( $t ) {
00070         return wfSetVar( $this->mCacheTime, $t );
00071     }
00072 
00077     function getCacheRevisionId() {
00078         return $this->mCacheRevisionId;
00079     }
00080 
00085     function setCacheRevisionId( $id ) {
00086         $this->mCacheRevisionId = $id;
00087     }
00088 
00099     function updateCacheExpiry( $seconds ) {
00100         $seconds = (int)$seconds;
00101 
00102         if ( $this->mCacheExpiry === null || $this->mCacheExpiry > $seconds ) {
00103             $this->mCacheExpiry = $seconds;
00104         }
00105 
00106         // hack: set old-style marker for uncacheable entries.
00107         if ( $this->mCacheExpiry !== null && $this->mCacheExpiry <= 0 ) {
00108             $this->mCacheTime = -1;
00109         }
00110     }
00111 
00121     function getCacheExpiry() {
00122         global $wgParserCacheExpireTime;
00123 
00124         if ( $this->mCacheTime < 0 ) {
00125             return 0;
00126         } // old-style marker for "not cachable"
00127 
00128         $expire = $this->mCacheExpiry;
00129 
00130         if ( $expire === null ) {
00131             $expire = $wgParserCacheExpireTime;
00132         } else {
00133             $expire = min( $expire, $wgParserCacheExpireTime );
00134         }
00135 
00136         if ( $this->containsOldMagic() ) { //compatibility hack
00137             $expire = min( $expire, 3600 ); # 1 hour
00138         }
00139 
00140         if ( $expire <= 0 ) {
00141             return 0; // not cachable
00142         } else {
00143             return $expire;
00144         }
00145     }
00146 
00150     function isCacheable() {
00151         return $this->getCacheExpiry() > 0;
00152     }
00153 
00162     public function expired( $touched ) {
00163         global $wgCacheEpoch;
00164         return !$this->isCacheable() || // parser says it's uncacheable
00165             $this->getCacheTime() < $touched ||
00166             $this->getCacheTime() <= $wgCacheEpoch ||
00167             $this->getCacheTime() < wfTimestamp( TS_MW, time() - $this->getCacheExpiry() ) || // expiry period has passed
00168             !isset( $this->mVersion ) ||
00169             version_compare( $this->mVersion, Parser::VERSION, "lt" );
00170     }
00171 
00184     public function isDifferentRevision( $id ) {
00185         $cached = $this->getCacheRevisionId();
00186         return $cached !== null && $id !== $cached;
00187     }
00188 }