Skip to content

fix(recommendations): invalidate all cache variants via pattern matching#938

Merged
RUKAYAT-CODER merged 3 commits into
rinafcode:mainfrom
Peaostrel:fix/issue-816-recommendation-cache
Jun 29, 2026
Merged

fix(recommendations): invalidate all cache variants via pattern matching#938
RUKAYAT-CODER merged 3 commits into
rinafcode:mainfrom
Peaostrel:fix/issue-816-recommendation-cache

Conversation

@Peaostrel

Copy link
Copy Markdown
Contributor

Fixes #816

Overview

Previously, invalidate() in RecommendationEngineService only 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

  • Added deleteByPattern to CachingService: Natively uses Redis SCAN + DEL for safe, non-blocking cache invalidation of pattern-matched keys. It gracefully falls back to .keys() for non-Redis cache stores.
  • Updated invalidate(): Modified RecommendationEngineService to delete all keys matching the recommendations:{userId}:* namespace prefix instead of an array of hardcoded limits.
  • Updated Tests: Added tests for deleteByPattern and updated recommendation engine specs to mock and verify the new pattern deletion logic.

Acceptance Criteria Met

  • All recommendation cache variants are invalidated when a new enrollment occurs.
  • invalidate() is idempotent and safe to call when no cached key exists (Redis SCAN handles empty matches safely and efficiently without throwing errors).

- added deleteByPattern to CachingService
- update invalidate() to clear all limits for a user
@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER RUKAYAT-CODER merged commit cffe34b into rinafcode:main Jun 29, 2026
2 checks passed
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.

RecommendationEngineService cache invalidation only covers four hardcoded limit values

2 participants