You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. I suggest implementing cache tags using Redis sets, similar to how it's done in Laravel. It's a more efficient way to retrieve a group of keys than using scan. What do you think about this approach? I can start working on a PR if everyone agrees.
**/cache/src/Driver/RedisDriver.php**
public function set($key, $value, $ttl = null, $tag = null): bool
{
$seconds = $this->secondsUntil($ttl);
$res = $this->packer->pack($value);
if ($seconds > 0) {
$setResult = $this->redis->set($this->getCacheKey($key), $res, $seconds);
} else {
$setResult = $this->redis->set($this->getCacheKey($key), $res);
}
if ($tag && $setResult) {
// Add key to tag set
$this->redis->sAdd("tag:{$tag}", $this->getCacheKey($key));
}
return $setResult;
}
public function deleteTag(string $tag): bool
{
$members = $this->redis->smembers("tag:{$tag}");
if ($members) {
// Delete each member key
$this->redis->del(...$members);
}
// Delete the set itself
return $this->redis->del("tag:{$tag}") == 1;
}
However, to facilitate this, we would need to create a custom CacheInterface as the current PSR-16 CacheInterface doesn't provide a method for cache tagging. This would mean adding the $tag parameter to the set method and introducing a new deleteTag method.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello. I suggest implementing cache tags using Redis sets, similar to how it's done in Laravel. It's a more efficient way to retrieve a group of keys than using scan. What do you think about this approach? I can start working on a PR if everyone agrees.
However, to facilitate this, we would need to create a custom
CacheInterface
as the current PSR-16CacheInterface
doesn't provide a method for cache tagging. This would mean adding the$tag
parameter to theset
method and introducing a newdeleteTag
method.Beta Was this translation helpful? Give feedback.
All reactions