Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor: unify cache access by requiring direct GetWithFetch#60

Merged
appleboy merged 2 commits intomainfrom
cache2
Feb 28, 2026
Merged

refactor: unify cache access by requiring direct GetWithFetch#60
appleboy merged 2 commits intomainfrom
cache2

Conversation

@appleboy
Copy link
Member

  • 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.

…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]>
Copilot AI review requested due to automatic review settings February 28, 2026 06:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 GetWithFetch into the cache.Cache[T] interface and remove the old WithFetch interface and generic helper.
  • Implement GetWithFetch on MemoryCache and RueidisCache, and update service/metrics call sites and tests accordingly.
  • Document the Redis >= 7.0 requirement for redis-aside across 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]>
@appleboy appleboy merged commit 98371a2 into main Feb 28, 2026
16 checks passed
@appleboy appleboy deleted the cache2 branch February 28, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants