Skip to content

Commit

Permalink
work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
januabisconti committed Nov 27, 2024
1 parent 4c37d4e commit f6e7ca3
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/SuperCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit f6e7ca3

Please sign in to comment.