MediaWiki  REL1_20
CacheTime.php
Go to the documentation of this file.
00001 <?php
00029 class CacheTime {
00030 
00031         var     $mVersion = Parser::VERSION,  # Compatibility check
00032                 $mCacheTime = '',             # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
00033                 $mCacheExpiry = null,         # Seconds after which the object should expire, use 0 for uncachable. Used in ParserCache.
00034                 $mContainsOldMagic;           # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
00035 
00036         function getCacheTime()              { return $this->mCacheTime; }
00037 
00038         function containsOldMagic()          { return $this->mContainsOldMagic; }
00039         function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
00040 
00047         function setCacheTime( $t )          { return wfSetVar( $this->mCacheTime, $t ); }
00048 
00059         function updateCacheExpiry( $seconds ) {
00060                 $seconds = (int)$seconds;
00061 
00062                 if ( $this->mCacheExpiry === null || $this->mCacheExpiry > $seconds ) {
00063                         $this->mCacheExpiry = $seconds;
00064                 }
00065 
00066                 // hack: set old-style marker for uncacheable entries.
00067                 if ( $this->mCacheExpiry !== null && $this->mCacheExpiry <= 0 ) {
00068                         $this->mCacheTime = -1;
00069                 }
00070         }
00071 
00081         function getCacheExpiry() {
00082                 global $wgParserCacheExpireTime;
00083 
00084                 if ( $this->mCacheTime < 0 ) {
00085                         return 0;
00086                 } // old-style marker for "not cachable"
00087 
00088                 $expire = $this->mCacheExpiry;
00089 
00090                 if ( $expire === null ) {
00091                         $expire = $wgParserCacheExpireTime;
00092                 } else {
00093                         $expire = min( $expire, $wgParserCacheExpireTime );
00094                 }
00095 
00096                 if( $this->containsOldMagic() ) { //compatibility hack
00097                         $expire = min( $expire, 3600 ); # 1 hour
00098                 }
00099 
00100                 if ( $expire <= 0 ) {
00101                         return 0; // not cachable
00102                 } else {
00103                         return $expire;
00104                 }
00105         }
00106 
00110         function isCacheable() {
00111                 return $this->getCacheExpiry() > 0;
00112         }
00113 
00122         public function expired( $touched ) {
00123                 global $wgCacheEpoch;
00124                 return !$this->isCacheable() || // parser says it's uncacheable
00125                         $this->getCacheTime() < $touched ||
00126                         $this->getCacheTime() <= $wgCacheEpoch ||
00127                         $this->getCacheTime() < wfTimestamp( TS_MW, time() - $this->getCacheExpiry() ) || // expiry period has passed
00128                         !isset( $this->mVersion ) ||
00129                         version_compare( $this->mVersion, Parser::VERSION, "lt" );
00130         }
00131 
00132 }