* - $wgCachePages
* - $wgCacheEpoch
* - $wgUseFileCache
+ * - $wgCacheDirectory
* - $wgFileCacheDirectory
* - $wgUseGzip
*
public function fileCacheName() {
if( !$this->mFileCache ) {
- global $wgFileCacheDirectory, $wgRequest;
+ global $wgCacheDirectory, $wgFileCacheDirectory, $wgRequest;
+
+ if ( $wgFileCacheDirectory ) {
+ $dir = $wgFileCacheDirectory;
+ } elseif ( $wgCacheDirectory ) {
+ $dir = "$wgCacheDirectory/html";
+ } else {
+ throw new MWException( 'Please set $wgCacheDirectory in LocalSettings.php if you wish to use the HTML file cache' );
+ }
+
# Store raw pages (like CSS hits) elsewhere
$subdir = ($this->mType === 'raw') ? 'raw/' : '';
$key = $this->mTitle->getPrefixedDbkey();
if( $this->useGzip() )
$this->mFileCache .= '.gz';
- wfDebug( " fileCacheName() - {$this->mFileCache}\n" );
+ wfDebug( __METHOD__ . ": {$this->mFileCache}\n" );
}
return $this->mFileCache;
}
global $wgCacheEpoch;
if( !$this->isFileCached() ) return false;
- if( !$timestamp ) return true; // should be invalidated on change
$cachetime = $this->fileCacheTime();
$good = $timestamp <= $cachetime && $wgCacheEpoch <= $cachetime;
- wfDebug(" isFileCacheGood() - cachetime $cachetime, touched '{$timestamp}' epoch {$wgCacheEpoch}, good $good\n");
+ wfDebug( __METHOD__ . ": cachetime $cachetime, touched '{$timestamp}' epoch {$wgCacheEpoch}, good $good\n");
return $good;
}
/* Working directory to/from output */
public function loadFromFileCache() {
global $wgOut, $wgMimeType, $wgOutputEncoding, $wgContLanguageCode;
- wfDebug(" loadFromFileCache()\n");
-
+ wfDebug( __METHOD__ . "()\n");
$filename = $this->fileCacheName();
// Raw pages should handle cache control on their own,
// even when using file cache. This reduces hits from clients.
}
}
readfile( $filename );
+ $wgOut->disable(); // tell $wgOut that output is taken care of
}
protected function checkCacheDirs() {
wfMkdirParents( $mydir2 );
}
- public function saveToFileCache( $origtext ) {
+ public function saveToFileCache( $text ) {
global $wgUseFileCache;
- if( !$wgUseFileCache ) {
- return $origtext; // return to output
+ if( !$wgUseFileCache || strlen( $text ) < 512 ) {
+ // Disabled or empty/broken output (OOM and PHP errors)
+ return $text;
}
- $text = $origtext;
- if( strcmp($text,'') == 0 ) return '';
- wfDebug(" saveToFileCache()\n", false);
+ wfDebug( __METHOD__ . "()\n", false);
$this->checkCacheDirs();