feat(cache): unified cache-aside abstraction with tag-based invalidation - #2166
Merged
RUKAYAT-CODER merged 2 commits intoAug 18, 2026
Merged
Conversation
…ion (EarnQuestOne#2159) Caching was applied ad-hoc per service with no shared key scheme or coordinated invalidation. Add a single cache-aside layer with namespaced keys and tag-based invalidation across the hot read paths: - CacheService.getOrSet(key, ttl, tags, loader) and invalidateTag(tag) unify the read/populate/invalidate flow over the existing tag registry. - New cache-tags.ts defines the namespaced key + tag conventions (CacheKeys, CacheTags, CacheTtl). - New CacheableInterceptor + @Cacheable() decorator let read endpoints opt in declaratively; registered/exported from CacheModule. - Quest listing, user profile (findById), and platform-analytics reads now go through getOrSet with tags, and the corresponding writes emit invalidateTag.
…-tag-invalidation # Conflicts: # BackEnd/src/modules/analytics/CHANGELOG.md # BackEnd/src/modules/analytics/services/platform-analytics.service.ts
Contributor
|
Thank you for contributing to the project. |
5 tasks
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.
Closes #2159
Summary
Caching was applied ad-hoc per service with no shared key scheme or coordinated invalidation, making stale reads and cache/DB divergence easy to introduce. This PR adds a single cache-aside layer with namespaced keys and tag-based invalidation across the hot read paths.
Changes
CacheServiceprimitives (src/modules/cache/cache.service.ts) —getOrSet(key, ttl, tags, loader)andinvalidateTag(tag), layered over the service's existing tag registry (set(..., tags)/invalidateByTag), so read/populate and coordinated invalidation share one flow.src/modules/cache/cache-tags.ts, new) —CacheKeys,CacheTags, andCacheTtldefine namespaced keys and the tags (quest:<id>,quest:list,user:<id>,analytics:platform) that group derived entries.src/common/interceptors/cacheable.interceptor.ts, new) —CacheableInterceptor+@Cacheable()decorator back a handler withgetOrSet; handlers without the metadata pass through untouched. Registered and exported fromCacheModule.getOrSetwith tags, emittinginvalidateTagon the matching writes:QuestsService—findAll/findOnecached;create/update/removeinvalidate the quest/list tags.UsersService.findById— cached per-user;updateinvalidatesuser:<id>.PlatformAnalyticsService.getPlatformStats— served through the unified cache taggedanalytics:platform(the existing snapshot path is preserved inresolvePlatformStats).Notes
CacheModuleis@Global, so the new injections resolve everywhere without extra module wiring; backward compatible (reads fall back to the loader on a miss, exactly as before).cache,users, andanalyticsmoduleCHANGELOG.mdfiles updated under[Unreleased].Verified locally:
npm run build,npm run lint(0 errors),prettier --check,npm run openapi:generate(app bootstraps, spec generated), and the backend module changelog-discipline check all pass.