Conversation
…ntations - Add Redis >= 7.0 requirement notes for `redis-aside` mode in documentation. - Remove the generic `GetWithFetch` helper and require all Cache implementations to provide a `GetWithFetch` method directly. - Implement `GetWithFetch` for `MemoryCache` and `RueidisCache` types. - Update service and metrics code to call the new `GetWithFetch` method directly, removing previous runtime interface assertions and fallbacks. - Refactor tests and cache spies to match the new interface and approach. Signed-off-by: appleboy <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the caching layer to standardize cache-aside access through a required GetWithFetch method on the core cache.Cache[T] interface, eliminating the previous helper/type-assertion fallback approach. It also updates documentation to clarify that redis-aside requires Redis >= 7.0 (RESP3 client-side caching).
Changes:
- Move
GetWithFetchinto thecache.Cache[T]interface and remove the oldWithFetchinterface and generic helper. - Implement
GetWithFetchonMemoryCacheandRueidisCache, and update service/metrics call sites and tests accordingly. - Document the Redis >= 7.0 requirement for
redis-asideacross docs and README.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/cache/interface.go | Makes GetWithFetch a required method on Cache[T] and removes the old helper/interface split. |
| internal/cache/memory.go | Adds MemoryCache.GetWithFetch implementation and compile-time interface conformance check. |
| internal/cache/rueidis.go | Adds RueidisCache.GetWithFetch implementation and compile-time interface conformance check. |
| internal/cache/rueidis_aside.go | Adds compile-time interface conformance check for RueidisAsideCache. |
| internal/services/user.go | Switches user service cache-aside calls to s.userCache.GetWithFetch(...) directly. |
| internal/services/user_test.go | Updates cache spy/test to match the new required GetWithFetch API and verify it’s called. |
| internal/metrics/cache.go | Simplifies metrics cache-aside usage to call m.cache.GetWithFetch(...) directly. |
| internal/metrics/cache_test.go | Updates mocks/tests to track GetWithFetch calls under the new interface. |
| internal/cache/cache_test.go | Refactors tests to call MemoryCache.GetWithFetch directly and adds new cases. |
| docs/PERFORMANCE.md | Adds Redis >= 7.0 requirement note for redis-aside. |
| docs/CONFIGURATION.md | Adds Redis >= 7.0 requirement note for redis-aside backend configuration. |
| README.md | Notes Redis >= 7.0 requirement for redis-aside in deployment guidance. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add a unit test to verify cache expiration and refetch behavior in MemoryCache Signed-off-by: appleboy <[email protected]>
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.
redis-asidemode in documentation.GetWithFetchhelper and require all Cache implementations to provide aGetWithFetchmethod directly.GetWithFetchforMemoryCacheandRueidisCachetypes.GetWithFetchmethod directly, removing previous runtime interface assertions and fallbacks.