Skip to content

[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

Closed
wants to merge 1 commit into from

Conversation

vtsykun
Copy link
Contributor

@vtsykun vtsykun commented Sep 8, 2023

Q A
Branch? 6.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #45599
License MIT
Doc PR -

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

  • colon is only allowed for Symfony contracts cache, the PSR-6/16 adapters keeps this validation as before.
  • Allow colon in namespace name too

@carsonbot carsonbot added this to the 6.4 milestone Sep 8, 2023
@vtsykun vtsykun force-pushed the feat/cache-1 branch 2 times, most recently from 24881eb to 94ec24f Compare September 9, 2023 11:28
{
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);
Copy link
Member

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));
Copy link
Member

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?

@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 7.1 Nov 15, 2023
@nicolas-grekas
Copy link
Member

@vtsykun up to resume this PR?

@dorrogeray
Copy link
Contributor

It would be great to have this feature 👍 I can try to pick up this PR @vtsykun if you are too busy.

@nicolas-grekas
Copy link
Member

@dorrogeray follow up PR welcome then!

@dorrogeray
Copy link
Contributor

@nicolas-grekas I will work on it this week.

@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 15, 2024
@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@nicolas-grekas
Copy link
Member

Closing in favor of #59813, thanks for giving this a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Cache] Allow colon in key key (with redis at least)
6 participants