feat: Implement centralized cache invalidation service#847
Open
softnationz wants to merge 1 commit into
Open
Conversation
- Enhanced cache.service.ts with new API methods: get, set, del, delPattern, getOrSet
- Added comprehensive namespaced key support (market:{id}, leaderboard:global:*, user:{id}:balance)
- Implemented pattern-based cache invalidation using Redis SCAN
- Updated MarketService to use new cache API and invalidate caches after writes
- Added 23 unit tests covering all cache operations and edge cases
- Included detailed documentation in CACHE_SERVICE_README.md
- Maintained backward compatibility with legacy API (cacheGet, cacheSet, etc.)
Resolves Netwalls#60
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 #457
This PR implements a centralized cache invalidation service to prevent stale reads in the BOXMEOUT platform. The service provides a clean API for cache operations with automatic invalidation when underlying data changes.
Changes
Core Service Enhancements (
cache.service.ts)get<T>(key)- Type-safe cache retrievalset(key, value, ttl)- Cache storage with TTLdel(key)- Single key deletiondelPattern(pattern)- Pattern-based bulk invalidation using Redis SCANgetOrSet<T>(key, ttl, compute)- Read-through caching patternCache Key Namespaces
Implemented consistent namespacing for organized cache management:
market:{id}- Individual market datamarket:{id}:stats- Market statisticsmarkets:*- Market list queriesleaderboard:global:*- Global leaderboard datauser:{id}:balance- User balance dataplatform:stats- Platform-wide statisticsMarketService Integration
invalidateMarketCache()for comprehensive market cache clearingbulkPauseMarkets()andbulkCancelMarkets()Testing
Documentation
CACHE_SERVICE_README.mdwith:Acceptance Criteria
cache.service.tsexposes:get,set,del,delPattern,getOrSetdelPattern('market:*')purges all market cache entries using Redis SCANmarket:{id},leaderboard:global:*,user:{id}:balancemarket.service.ts, relevant cache keys are invalidated