From 8cbd865d2cec0194ef60338332ce0d1271f4487c Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Tue, 7 Feb 2012 20:47:45 +0000 Subject: [PATCH] simplify FileCacheBase::fetchText Implements a proposal by Tim on r98405 CR --- includes/cache/FileCacheBase.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/includes/cache/FileCacheBase.php b/includes/cache/FileCacheBase.php index 00fe995793..29cc8a13fc 100644 --- a/includes/cache/FileCacheBase.php +++ b/includes/cache/FileCacheBase.php @@ -116,12 +116,9 @@ abstract class FileCacheBase { * @return string */ public function fetchText() { - if ( $this->useGzip() ) { - /* Why is there no gzfile_get_contents() or gzdecode()? */ - return implode( '', gzfile( $this->cachePath() ) ); - } else { - return file_get_contents( $this->cachePath() ); - } + // gzopen can transparently read from gziped or plain text + $fh = gzopen( $this->cachePath(), 'r' ); + return stream_get_contents( $fh ); } /** @@ -141,6 +138,7 @@ abstract class FileCacheBase { $this->checkCacheDirs(); // build parent dir if ( !file_put_contents( $this->cachePath(), $text, LOCK_EX ) ) { + wfDebug( __METHOD__ . "() failed saving ". $this->cachePath() . "\n"); $this->mCached = null; return false; } -- 2.20.1