From f6e7ca33efc3777a3dd6372d073549d6911880bd Mon Sep 17 00:00:00 2001 From: janua bisconti Date: Wed, 27 Nov 2024 17:07:30 +0100 Subject: [PATCH] work in progress --- src/SuperCacheManager.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/SuperCacheManager.php b/src/SuperCacheManager.php index d038e59..020e8a5 100644 --- a/src/SuperCacheManager.php +++ b/src/SuperCacheManager.php @@ -144,9 +144,13 @@ public function get(string $key, ?string $connection_name = null): mixed /** * Rimuove una chiave dalla cache e dai suoi set di tag. */ - public function forget(string $key, ?string $connection_name = null): void + public function forget(string $key, ?string $connection_name = null, ?bool $isFinalKey = false): void { - $finalKey = $this->getFinalKey($key); + if ($isFinalKey) { + $finalKey = $key; + } else { + $finalKey = $this->getFinalKey($key); + } // Recupera i tag associati alla chiave $tags = $this->redis->getRedisConnection($connection_name)->smembers($this->prefix . 'tags:' . $finalKey); @@ -172,6 +176,19 @@ public function forget(string $key, ?string $connection_name = null): void } } + public function flushByTags(array $tags, ?string $connection_name = null): void + { + // ATTENZIONE, non si può fare in pipeline perchè ci sono anche comandi Redis che hanno bisogno di una promise + // perchè restituiscono dei valori necessari alle istruzioni successive + foreach ($tags as $tag) { + $keys = $this->getKeysOfTag($tag, $connection_name); + foreach ($keys as $key) { + // Con questo cancello sia i tag che le chiavi + $this->forget($key, $connection_name, true); + } + } + } + /** * Recupera tutti i tag associati a una chiave. */ @@ -314,6 +331,7 @@ public function lock(string $key, ?string $connection_name = null, ?int $ttl = 1 if ($ttl !== null) { $this->redis->getRedisConnection($connection_name)->expire($finalKey, $ttl); } + return true; }