Skip to content

Commit

Permalink
Merge pull request #300 from opcodesio/bug/malformed-characters
Browse files Browse the repository at this point in the history
only enable index cache on certain cache drivers
  • Loading branch information
arukompas authored Nov 19, 2023
2 parents 4f0a90f + af0faa2 commit 68d9f76
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Concerns/LogIndex/CanCacheIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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));
}

Expand Down

0 comments on commit 68d9f76

Please sign in to comment.