From af0faa2ff3ce5027e01b0429269570f2b69ff7f0 Mon Sep 17 00:00:00 2001 From: Arunas Skirius Date: Sun, 19 Nov 2023 09:32:13 +0200 Subject: [PATCH] only enable index cache on certain cache drivers --- src/Concerns/LogIndex/CanCacheIndex.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Concerns/LogIndex/CanCacheIndex.php b/src/Concerns/LogIndex/CanCacheIndex.php index 4d19c884..4543f99a 100644 --- a/src/Concerns/LogIndex/CanCacheIndex.php +++ b/src/Concerns/LogIndex/CanCacheIndex.php @@ -49,11 +49,17 @@ protected function getMetadataFromCache(): array return Cache::get($this->metaCacheKey(), []); } + protected function canUseCompression(): bool + { + return extension_loaded('zlib') + && in_array(config('cache.default'), ['file', 'redis', 'array']); + } + protected function saveChunkToCache(LogIndexChunk $chunk): void { $data = $chunk->data; - if (extension_loaded('zlib')) { + if ($this->canUseCompression()) { $data = gzcompress(serialize($data), 1); } @@ -68,7 +74,7 @@ protected function getChunkDataFromCache(int $index, $default = null): ?array { $data = Cache::get($this->chunkCacheKey($index), $default); - if (is_string($data) && extension_loaded('zlib')) { + if (is_string($data) && $this->canUseCompression()) { $data = unserialize(gzuncompress($data)); }