-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Cache] Allow to use namespace delimiter in cache key #51603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
24881eb
to
94ec24f
Compare
94ec24f
to
89a1d78
Compare
{ | ||
if (!\is_string($key)) { | ||
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key))); | ||
} | ||
if ('' === $key) { | ||
throw new InvalidArgumentException('Cache key length must be greater than zero.'); | ||
} | ||
if (false !== strpbrk($key, self::RESERVED_CHARACTERS)) { | ||
throw new InvalidArgumentException(sprintf('Cache key "%s" contains reserved characters "%s".', $key, self::RESERVED_CHARACTERS)); | ||
$reservedChars = null === $allowChars ? self::RESERVED_CHARACTERS : str_replace(str_split($allowChars), '', self::RESERVED_CHARACTERS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be possible to get rid of the calls to str_replace and str_split? this is on the hotpath and we'd better make this as fast as possible
@@ -346,7 +346,7 @@ protected function getId(mixed $key): string | |||
if (\is_string($key) && isset($this->ids[$key])) { | |||
return $this->namespace.$this->namespaceVersion.$this->ids[$key]; | |||
} | |||
\assert('' !== CacheItem::validateKey($key)); | |||
\assert('' !== CacheItem::validateKey($key, static::NS_SEPARATOR)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one is used for PSR-6 also, isn't it?
@vtsykun up to resume this PR? |
It would be great to have this feature 👍 I can try to pick up this PR @vtsykun if you are too busy. |
@dorrogeray follow up PR welcome then! |
@nicolas-grekas I will work on it this week. |
Closing in favor of #59813, thanks for giving this a try! |
This PR allow colon char
:
in cache key. It may be useful for redis grouping keys by pattern without creating a many pools for each namespace.Difference between implementation #47561