MediaWiki  1.23.12
ResourceFileCache.php
Go to the documentation of this file.
1 <?php
30  protected $mCacheWorthy;
31 
32  /* @todo configurable? */
33  const MISS_THRESHOLD = 360; // 6/min * 60 min
34 
40  public static function newFromContext( ResourceLoaderContext $context ) {
41  $cache = new self();
42 
43  if ( $context->getOnly() === 'styles' ) {
44  $cache->mType = 'css';
45  } else {
46  $cache->mType = 'js';
47  }
48  $modules = array_unique( $context->getModules() ); // remove duplicates
49  sort( $modules ); // normalize the order (permutation => combination)
50  $cache->mKey = sha1( $context->getHash() . implode( '|', $modules ) );
51  if ( count( $modules ) == 1 ) {
52  $cache->mCacheWorthy = true; // won't take up much space
53  }
54 
55  return $cache;
56  }
57 
64  public static function useFileCache( ResourceLoaderContext $context ) {
65  global $wgUseFileCache, $wgDefaultSkin, $wgLanguageCode;
66  if ( !$wgUseFileCache ) {
67  return false;
68  }
69  // Get all query values
70  $queryVals = $context->getRequest()->getValues();
71  foreach ( $queryVals as $query => $val ) {
72  if ( $query === 'modules' || $query === 'version' || $query === '*' ) {
73  continue; // note: &* added as IE fix
74  } elseif ( $query === 'skin' && $val === $wgDefaultSkin ) {
75  continue;
76  } elseif ( $query === 'lang' && $val === $wgLanguageCode ) {
77  continue;
78  } elseif ( $query === 'only' && in_array( $val, array( 'styles', 'scripts' ) ) ) {
79  continue;
80  } elseif ( $query === 'debug' && $val === 'false' ) {
81  continue;
82  }
83 
84  return false;
85  }
86 
87  return true; // cacheable
88  }
89 
94  protected function cacheDirectory() {
95  return $this->baseCacheDirectory() . '/resources';
96  }
97 
102  public function isCacheWorthy() {
103  if ( $this->mCacheWorthy === null ) {
104  $this->mCacheWorthy = (
105  $this->isCached() || // even stale cache indicates it was cache worthy
106  $this->getMissesRecent() >= self::MISS_THRESHOLD // many misses
107  );
108  }
109 
110  return $this->mCacheWorthy;
111  }
112 }
ResourceLoaderContext
Object passed around to modules which contains information about the state of a specific loader reque...
Definition: ResourceLoaderContext.php:29
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ResourceFileCache\newFromContext
static newFromContext(ResourceLoaderContext $context)
Construct an ResourceFileCache from a context.
Definition: ResourceFileCache.php:40
ResourceLoaderContext\getModules
getModules()
Definition: ResourceLoaderContext.php:136
ResourceLoaderContext\getOnly
getOnly()
Definition: ResourceLoaderContext.php:189
ResourceLoaderContext\getRequest
getRequest()
Definition: ResourceLoaderContext.php:129
ResourceFileCache\$mCacheWorthy
$mCacheWorthy
Definition: ResourceFileCache.php:30
FileCacheBase\baseCacheDirectory
baseCacheDirectory()
Get the base file cache directory.
Definition: FileCacheBase.php:52
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ResourceFileCache\useFileCache
static useFileCache(ResourceLoaderContext $context)
Check if an RL request can be cached.
Definition: ResourceFileCache.php:64
FileCacheBase\isCached
isCached()
Check if the cache file exists.
Definition: FileCacheBase.php:91
FileCacheBase\getMissesRecent
getMissesRecent()
Roughly gets the cache misses in the last hour by unique visitors.
Definition: FileCacheBase.php:271
$cache
$cache
Definition: mcc.php:32
ResourceFileCache\MISS_THRESHOLD
const MISS_THRESHOLD
Definition: ResourceFileCache.php:33
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ResourceLoaderContext\getHash
getHash()
Definition: ResourceLoaderContext.php:231
ResourceFileCache\isCacheWorthy
isCacheWorthy()
Item has many recent cache misses.
Definition: ResourceFileCache.php:102
$query
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1105
ResourceFileCache
Resource loader request result caching in the file system.
Definition: ResourceFileCache.php:29
ResourceFileCache\cacheDirectory
cacheDirectory()
Get the base file cache directory.
Definition: ResourceFileCache.php:94
FileCacheBase
Base class for data storage in the file system.
Definition: FileCacheBase.php:29