MediaWiki
REL1_22
|
00001 <?php 00029 class ResourceFileCache extends FileCacheBase { 00030 protected $mCacheWorthy; 00031 00032 /* @todo configurable? */ 00033 const MISS_THRESHOLD = 360; // 6/min * 60 min 00034 00040 public static function newFromContext( ResourceLoaderContext $context ) { 00041 $cache = new self(); 00042 00043 if ( $context->getOnly() === 'styles' ) { 00044 $cache->mType = 'css'; 00045 } else { 00046 $cache->mType = 'js'; 00047 } 00048 $modules = array_unique( $context->getModules() ); // remove duplicates 00049 sort( $modules ); // normalize the order (permutation => combination) 00050 $cache->mKey = sha1( $context->getHash() . implode( '|', $modules ) ); 00051 if ( count( $modules ) == 1 ) { 00052 $cache->mCacheWorthy = true; // won't take up much space 00053 } 00054 00055 return $cache; 00056 } 00057 00064 public static function useFileCache( ResourceLoaderContext $context ) { 00065 global $wgUseFileCache, $wgDefaultSkin, $wgLanguageCode; 00066 if ( !$wgUseFileCache ) { 00067 return false; 00068 } 00069 // Get all query values 00070 $queryVals = $context->getRequest()->getValues(); 00071 foreach ( $queryVals as $query => $val ) { 00072 if ( $query === 'modules' || $query === 'version' || $query === '*' ) { 00073 continue; // note: &* added as IE fix 00074 } elseif ( $query === 'skin' && $val === $wgDefaultSkin ) { 00075 continue; 00076 } elseif ( $query === 'lang' && $val === $wgLanguageCode ) { 00077 continue; 00078 } elseif ( $query === 'only' && in_array( $val, array( 'styles', 'scripts' ) ) ) { 00079 continue; 00080 } elseif ( $query === 'debug' && $val === 'false' ) { 00081 continue; 00082 } 00083 return false; 00084 } 00085 return true; // cacheable 00086 } 00087 00092 protected function cacheDirectory() { 00093 return $this->baseCacheDirectory() . '/resources'; 00094 } 00095 00100 public function isCacheWorthy() { 00101 if ( $this->mCacheWorthy === null ) { 00102 $this->mCacheWorthy = ( 00103 $this->isCached() || // even stale cache indicates it was cache worthy 00104 $this->getMissesRecent() >= self::MISS_THRESHOLD // many misses 00105 ); 00106 } 00107 return $this->mCacheWorthy; 00108 } 00109 }