simplify FileCacheBase::fetchText
authorAntoine Musso <hashar@users.mediawiki.org>
Tue, 7 Feb 2012 20:47:45 +0000 (20:47 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Tue, 7 Feb 2012 20:47:45 +0000 (20:47 +0000)
Implements a proposal by Tim on r98405 CR

includes/cache/FileCacheBase.php

index 00fe995..29cc8a1 100644 (file)
@@ -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;
                }