Go to the documentation of this file.
24 use Wikimedia\IPUtils;
71 if ( $this->mFilePath !==
null ) {
76 # Build directories (methods include the trailing "/")
78 # Avoid extension confusion
79 $key = str_replace(
'.',
'%2E', urlencode( $this->mKey ) );
80 # Build the full file path
81 $this->mFilePath =
"{$dir}/{$subDirs}{$key}.{$this->mExt}";
83 $this->mFilePath .=
'.gz';
94 if ( $this->mCached ===
null ) {
95 $this->mCached = file_exists( $this->
cachePath() );
106 $timestamp = filemtime( $this->
cachePath() );
108 return ( $timestamp !==
false )
127 $good = ( $timestamp <= $cachetime &&
$wgCacheEpoch <= $cachetime );
129 ": cachetime $cachetime, touched '{$timestamp}' epoch {$wgCacheEpoch}, good $good" );
148 $fh = gzopen( $this->
cachePath(),
'rb' );
150 return stream_get_contents( $fh );
152 return file_get_contents( $this->
cachePath() );
163 $text = gzencode( $text );
167 if ( !file_put_contents( $this->
cachePath(), $text, LOCK_EX ) ) {
169 $this->mCached =
null;
174 $this->mCached =
true;
184 Wikimedia\suppressWarnings();
186 Wikimedia\restoreWarnings();
187 $this->mCached =
false;
206 return $this->mType .
'/';
219 $hash = md5( $this->mKey );
221 $subdir .= substr( $hash, 0, $i ) .
'/';
234 if ( mt_rand( 0, self::MISS_FACTOR - 1 ) == 0 ) {
235 # Get a large IP range that should include the user even if that
236 # person's IP address changes
237 $ip = $request->
getIP();
238 if ( !IPUtils::isValid( $ip ) ) {
242 $ip = IPUtils::isIPv6( $ip )
243 ? IPUtils::sanitizeRange(
"$ip/32" )
244 : IPUtils::sanitizeRange(
"$ip/16" );
246 # Bail out if a request already came from this range...
248 $key =
$cache->makeKey( static::class,
'attempt', $this->mType, $this->mKey, $ip );
249 if ( !
$cache->add( $key, 1, self::MISS_TTL_SEC ) ) {
253 # Increment the number of cache misses...
273 return $cache->makeKey( static::class,
'misses', $this->mType, $this->mKey );
cacheMissKey(BagOStuff $cache)
static getLocalClusterInstance()
Get the main cluster-local cache object.
saveText( $text)
Save and compress text to the cache.
isCacheGood( $timestamp='')
Check if up to date cache file exists.
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Class representing a cache/ephemeral data store.
hashSubdirectory()
Return relative multi-level hash subdirectory (with trailing slash) or the empty string if not $wgFil...
useGzip()
Check if the cache is gzipped.
baseCacheDirectory()
Get the base file cache directory.
$wgUseGzip
When using the file cache, we can store the cached HTML gzipped to save disk space.
fetchText()
Get the uncompressed text from the cache.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
typeSubdirectory()
Get the cache type subdirectory (with trailing slash) An extending class could use that method to alt...
bool null $mCached
lazy loaded
$wgFileCacheDepth
Depth of the subdirectory hierarchy to be created under $wgFileCacheDirectory.
isCached()
Check if the cache file exists.
cacheDirectory()
Get the base cache directory (not specific to this file)
clearCache()
Clear the cache for this page.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
getIP()
Work out the IP address based on various globals For trusted proxies, use the XFF client IP (first of...
$wgCacheEpoch
Set this to current time to invalidate all prior cached pages.
getMissesRecent()
Roughly gets the cache misses in the last hour by unique visitors.
cachePath()
Get the path to the cache file.
$wgFileCacheDirectory
Directory where the cached page will be saved.
incrMissesRecent(WebRequest $request)
Roughly increments the cache misses in the last hour by unique visitors.
cacheTimestamp()
Get the last-modified timestamp of the cache file.
checkCacheDirs()
Create parent directors of $this->cachePath()
Base class for data storage in the file system.