Fix uncompressed cache

This commit is contained in:
eraseyourknees@gmail.com 2022-08-25 18:12:01 +02:00
parent 99f6e8d940
commit d5769f635c

View File

@ -17,6 +17,7 @@ limitations under the License.
class UupDumpCache { class UupDumpCache {
private $cacheFile; private $cacheFile;
private $isCompressed;
private $newCacheVersion = 1; private $newCacheVersion = 1;
public function __construct($resource, $compressed = true) { public function __construct($resource, $compressed = true) {
@ -24,6 +25,7 @@ class UupDumpCache {
$cacheHash = hash('sha256', strtolower($res)); $cacheHash = hash('sha256', strtolower($res));
$ext = $compressed ? '.json.gz' : '.json'; $ext = $compressed ? '.json.gz' : '.json';
$this->cacheFile = 'cache/'.$cacheHash.$ext; $this->cacheFile = 'cache/'.$cacheHash.$ext;
$this->isCompressed = $compressed;
} }
public function getFileName() { public function getFileName() {
@ -41,7 +43,9 @@ class UupDumpCache {
return false; return false;
} }
$cache = @gzdecode(@file_get_contents($cacheFile)); $cache = @file_get_contents($cacheFile);
if($this->isCompressed) $cache = @gzdecode($cache);
$cache = json_decode($cache, 1); $cache = json_decode($cache, 1);
$expires = $cache['expires']; $expires = $cache['expires'];
@ -65,6 +69,10 @@ class UupDumpCache {
); );
if(!file_exists('cache')) mkdir('cache'); if(!file_exists('cache')) mkdir('cache');
@file_put_contents($cacheFile, gzencode(json_encode($cache)."\n"));
$cacheContent = json_encode($cache)."\n";
if($this->isCompressed) $cacheContent = @gzencode($cache);
@file_put_contents($cacheFile, $cacheContent);
} }
} }