MediaWiki  master
FileCacheBase Class Reference

Base class for data storage in the file system. More...

Inheritance diagram for FileCacheBase:
Collaboration diagram for FileCacheBase:

Public Member Functions

 cacheTimestamp ()
 Get the last-modified timestamp of the cache file. More...
 
 clearCache ()
 Clear the cache for this page. More...
 
 fetchText ()
 Get the uncompressed text from the cache. More...
 
 getMissesRecent ()
 Roughly gets the cache misses in the last hour by unique visitors. More...
 
 incrMissesRecent (WebRequest $request)
 Roughly increments the cache misses in the last hour by unique visitors. More...
 
 isCached ()
 Check if the cache file exists. More...
 
 isCacheGood ( $timestamp='')
 Check if up to date cache file exists. More...
 
 saveText ( $text)
 Save and compress text to the cache. More...
 

Protected Member Functions

 __construct ()
 
 baseCacheDirectory ()
 Get the base file cache directory. More...
 
 cacheDirectory ()
 Get the base cache directory (not specific to this file) More...
 
 cacheMissKey (BagOStuff $cache)
 
 cachePath ()
 Get the path to the cache file. More...
 
 checkCacheDirs ()
 Create parent directors of $this->cachePath() More...
 
 hashSubdirectory ()
 Return relative multi-level hash subdirectory (with trailing slash) or the empty string if not $wgFileCacheDepth. More...
 
 typeSubdirectory ()
 Get the cache type subdirectory (with trailing slash) An extending class could use that method to alter the type -> directory mapping. More...
 
 useGzip ()
 Check if the cache is gzipped. More...
 

Protected Attributes

bool null $mCached
 lazy loaded More...
 
 $mExt = 'cache'
 
 $mFilePath
 
 $mKey
 
 $mType = 'object'
 
 $mUseGzip
 
ServiceOptions $options
 

Detailed Description

Base class for data storage in the file system.

Definition at line 35 of file FileCacheBase.php.

Constructor & Destructor Documentation

◆ __construct()

FileCacheBase::__construct ( )
protected

Definition at line 59 of file FileCacheBase.php.

Member Function Documentation

◆ baseCacheDirectory()

FileCacheBase::baseCacheDirectory ( )
finalprotected

Get the base file cache directory.

Returns
string

Definition at line 71 of file FileCacheBase.php.

Referenced by HTMLFileCache\cacheDirectory(), and ResourceFileCache\cacheDirectory().

◆ cacheDirectory()

FileCacheBase::cacheDirectory ( )
abstractprotected

Get the base cache directory (not specific to this file)

Returns
string

Reimplemented in ResourceFileCache, and HTMLFileCache.

Referenced by cachePath().

◆ cacheMissKey()

FileCacheBase::cacheMissKey ( BagOStuff  $cache)
protected
Parameters
BagOStuff$cacheInstance that the key will be used with
Returns
string

Definition at line 287 of file FileCacheBase.php.

References $cache.

Referenced by getMissesRecent(), and incrMissesRecent().

◆ cachePath()

FileCacheBase::cachePath ( )
protected

Get the path to the cache file.

Returns
string

Definition at line 85 of file FileCacheBase.php.

References $mFilePath, cacheDirectory(), hashSubdirectory(), typeSubdirectory(), and useGzip().

Referenced by cacheTimestamp(), checkCacheDirs(), clearCache(), fetchText(), isCached(), HTMLFileCache\loadFromFileCache(), and saveText().

◆ cacheTimestamp()

FileCacheBase::cacheTimestamp ( )

Get the last-modified timestamp of the cache file.

Returns
string|bool TS_MW timestamp

Definition at line 120 of file FileCacheBase.php.

References cachePath(), and wfTimestamp().

Referenced by isCacheGood(), and MediaWiki\ResourceLoader\ResourceLoader\tryRespondFromFileCache().

◆ checkCacheDirs()

FileCacheBase::checkCacheDirs ( )
protected

Create parent directors of $this->cachePath()

Returns
void

Definition at line 209 of file FileCacheBase.php.

References cachePath(), and wfMkdirParents().

Referenced by saveText().

◆ clearCache()

FileCacheBase::clearCache ( )

Clear the cache for this page.

Returns
void

Definition at line 198 of file FileCacheBase.php.

References cachePath().

◆ fetchText()

FileCacheBase::fetchText ( )

Get the uncompressed text from the cache.

Returns
string

Definition at line 161 of file FileCacheBase.php.

References cachePath(), and useGzip().

Referenced by MediaWiki\ResourceLoader\ResourceLoader\tryRespondFromFileCache().

◆ getMissesRecent()

FileCacheBase::getMissesRecent ( )

Roughly gets the cache misses in the last hour by unique visitors.

Returns
int

Definition at line 277 of file FileCacheBase.php.

References $cache, cacheMissKey(), and ObjectCache\getLocalClusterInstance().

Referenced by ResourceFileCache\isCacheWorthy().

◆ hashSubdirectory()

FileCacheBase::hashSubdirectory ( )
protected

Return relative multi-level hash subdirectory (with trailing slash) or the empty string if not $wgFileCacheDepth.

Returns
string

Definition at line 229 of file FileCacheBase.php.

Referenced by cachePath().

◆ incrMissesRecent()

FileCacheBase::incrMissesRecent ( WebRequest  $request)

Roughly increments the cache misses in the last hour by unique visitors.

Parameters
WebRequest$request
Returns
void

Definition at line 248 of file FileCacheBase.php.

References $cache, cacheMissKey(), WebRequest\getIP(), and ObjectCache\getLocalClusterInstance().

◆ isCached()

FileCacheBase::isCached ( )

Check if the cache file exists.

Returns
bool

Definition at line 108 of file FileCacheBase.php.

References $mCached, and cachePath().

Referenced by isCacheGood(), and ResourceFileCache\isCacheWorthy().

◆ isCacheGood()

FileCacheBase::isCacheGood (   $timestamp = '')

Check if up to date cache file exists.

Parameters
string$timestampMW_TS timestamp
Returns
bool

Definition at line 134 of file FileCacheBase.php.

References cacheTimestamp(), isCached(), wfBoolToStr(), and wfDebug().

Referenced by MediaWiki\ResourceLoader\ResourceLoader\tryRespondFromFileCache().

◆ saveText()

FileCacheBase::saveText (   $text)

Save and compress text to the cache.

Parameters
string$text
Returns
string|false Compressed text

Definition at line 176 of file FileCacheBase.php.

References cachePath(), checkCacheDirs(), useGzip(), and wfDebug().

Referenced by HTMLFileCache\saveToFileCache().

◆ typeSubdirectory()

FileCacheBase::typeSubdirectory ( )
protected

Get the cache type subdirectory (with trailing slash) An extending class could use that method to alter the type -> directory mapping.

See also
HTMLFileCache::typeSubdirectory() for an example.
Returns
string

Reimplemented in HTMLFileCache.

Definition at line 220 of file FileCacheBase.php.

Referenced by cachePath().

◆ useGzip()

FileCacheBase::useGzip ( )
protected

Check if the cache is gzipped.

Returns
bool

Definition at line 153 of file FileCacheBase.php.

References $mUseGzip.

Referenced by cachePath(), fetchText(), HTMLFileCache\loadFromFileCache(), saveText(), and HTMLFileCache\saveToFileCache().

Member Data Documentation

◆ $mCached

bool null FileCacheBase::$mCached
protected

lazy loaded

Definition at line 51 of file FileCacheBase.php.

Referenced by isCached().

◆ $mExt

FileCacheBase::$mExt = 'cache'
protected

Definition at line 47 of file FileCacheBase.php.

◆ $mFilePath

FileCacheBase::$mFilePath
protected

Definition at line 48 of file FileCacheBase.php.

Referenced by cachePath().

◆ $mKey

FileCacheBase::$mKey
protected
Initial value:
=[,,,,,]
private const CONSTRUCTOR_OPTIONS
MainConfigNames::CacheEpoch
MainConfigNames::FileCacheDepth
MainConfigNames::FileCacheDirectory
MainConfigNames::MimeType
MainConfigNames::UseGzip

Definition at line 45 of file FileCacheBase.php.

◆ $mType

FileCacheBase::$mType = 'object'
protected

Definition at line 46 of file FileCacheBase.php.

◆ $mUseGzip

FileCacheBase::$mUseGzip
protected

Definition at line 49 of file FileCacheBase.php.

Referenced by useGzip().

◆ $options

ServiceOptions FileCacheBase::$options
protected

Definition at line 53 of file FileCacheBase.php.


The documentation for this class was generated from the following file: