fix(recommendations): invalidate all cache variants via pattern matching#938
Merged
RUKAYAT-CODER merged 3 commits intoJun 29, 2026
Merged
Conversation
- added deleteByPattern to CachingService - update invalidate() to clear all limits for a user
|
@Peaostrel Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Thank you for contributing to the project. |
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.
Fixes #816
Overview
Previously,
invalidate()inRecommendationEngineServiceonly cleared recommendation cache variants for specific hardcoded limits (5, 10, 20, 50). If a client requested recommendations with custom limits (e.g., 15 or 100), those cache keys were never invalidated after a new enrollment, serving permanently stale recommendations.This PR resolves the issue by implementing a wildcard pattern deletion mechanism, ensuring all limit variants for a specific user are properly cleared.
Changes
deleteByPatterntoCachingService: Natively uses RedisSCAN+DELfor safe, non-blocking cache invalidation of pattern-matched keys. It gracefully falls back to.keys()for non-Redis cache stores.invalidate(): ModifiedRecommendationEngineServiceto delete all keys matching therecommendations:{userId}:*namespace prefix instead of an array of hardcoded limits.deleteByPatternand updated recommendation engine specs to mock and verify the new pattern deletion logic.Acceptance Criteria Met
invalidate()is idempotent and safe to call when no cached key exists (RedisSCANhandles empty matches safely and efficiently without throwing errors).