Skip to content

[Cache] Enable namespace-based invalidation by prefixing keys with backend-native namespace separators #59813

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

Merged
merged 1 commit into from
Mar 23, 2025

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Feb 19, 2025

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #45599
License MIT

This PR adds a NamespacedPoolInterface that describes how one can add namespace prefixes to cache pool keys.

This solves #45599 by allowing to use the : separator for Redis:

$cache->withSubNamespace('some-prefix')->get($key, fn () => ...);

Most importantly, this enables namespace-based cache invalidation, typically with namespaces generated by hashing some context.

@stof
Copy link
Member

stof commented Feb 19, 2025

If pushNamespace returns a new adapter, what is the use case for popNamespace (which also returns a new adapter, and so won't return the "parent" ArrayAdapter for instance) ?

@nicolas-grekas
Copy link
Member Author

@stof you're totally right! I removed popNamespace and renamed the pushNamespace method to withSubNamespace.

@nicolas-grekas nicolas-grekas force-pushed the cache-ns-relax branch 4 times, most recently from 904427d to 349fa7b Compare February 20, 2025 09:51
@nicolas-grekas
Copy link
Member Author

Ready. Tests should be green after merge.

@nicolas-grekas nicolas-grekas force-pushed the cache-ns-relax branch 2 times, most recently from b733583 to 80e4605 Compare February 21, 2025 07:52
@nicolas-grekas nicolas-grekas force-pushed the cache-ns-relax branch 3 times, most recently from da4eacf to b9b63de Compare March 13, 2025 15:23
@nicolas-grekas
Copy link
Member Author

PR ready (failures will be fixed by merging)

@nicolas-grekas
Copy link
Member Author

Any comment @symfony/mergers ?

Copy link
Member

@kbond kbond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@nicolas-grekas nicolas-grekas merged commit 6ef1ab4 into symfony:7.3 Mar 23, 2025
8 of 11 checks passed
@nicolas-grekas nicolas-grekas deleted the cache-ns-relax branch March 23, 2025 17:41
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)
5 participants