Repository navigation
Conversation
Add Cache.Tags, the optional DriverWithTags interface and the TaggedCache contract. The memory driver namespaces tagged items by their tags and keeps a tag to key mapping so flushing a tag removes every item stored under it. Drivers that don't implement DriverWithTags make Cache.Tags return CacheTagsNotSupported.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1579 +/- ##
==========================================
+ Coverage 72.91% 72.99% +0.08%
==========================================
Files 412 413 +1
Lines 26893 26992 +99
==========================================
+ Hits 19608 19703 +95
- Misses 7283 7287 +4
Partials 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
JGamboa
marked this pull request as ready for review
October 18, 2026 23:47
Contributor
Author
|
Review Ready |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📑 Description
Closes goravel/goravel#174
Adds cache tags, like Laravel's
Cache::tags(), and implements them in the memory driver, as suggested in the issue ("just add a mapping for tag and key"):contracts/cache):Cache.Tags(names ...string) (TaggedCache, error)on the default store.DriverWithTags.TaggedCache:Add,Increment/Decrement,Forever,Forget,Flush,Get*,Has,Put,Pull,Remember,RememberForever. It leaves outLock,WithContextandDocker, which are store-level.Driveris untouched, so custom and external drivers keep compiling. A store that doesn't implementDriverWithTagsreturnsCacheTagsNotSupported. For a non-default store:Store("x").(cache.DriverWithTags).sha1(join(tags, "|")), so tag order matters.Flushclears the index too.CacheTagsNotSupportedandCacheTagsRequired. Mocks are regenerated.Redis (follow-up PR in goravel/redis):
prefix:sha1(tags):key.prefix:tag:{name}:entriesof item keys, scored by expiry.PutdoesSET+ZADDin one pipeline. A tag flush reads the set withZRANGE, deletes the items in chunks, then deletes the set.While looking at this I noticed that today
Flushin the Redis driver usesFLUSHALL, which wipes the whole Redis database and not only the cache keys. I can open an issue for that separately.✅ Checks
cache/memory_tags_test.go: put/get, the same key under different tags, flushing by any tag, flushing an unknown tag,Add,Increment/Decrement,Forget/Pull, expiration,Remember, a store flush clearing the tags, pruning of the index, and concurrent put + flush. AlsoTestApplicationTagsfor the facade and the unsupported-driver error.