feat: write-path cache invalidation with per-org namespacing#899
Open
martinshub-tech wants to merge 1 commit into
Open
feat: write-path cache invalidation with per-org namespacing#899martinshub-tech wants to merge 1 commit into
martinshub-tech wants to merge 1 commit into
Conversation
|
@martinshub-tech 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! 🚀 |
| } | ||
| } catch (error) { | ||
| console.warn(`Redis get failed for key ${key}:`, error); | ||
| console.warn(`Redis get failed for key ${cacheKey}:`, error); |
| await redisClient.set(cacheKey, JSON.stringify(entry), 'EX', ttlSeconds); | ||
| } catch (error) { | ||
| console.warn(`Redis set failed for key ${key}:`, error); | ||
| console.warn(`Redis set failed for key ${cacheKey}:`, error); |
| await redisClient.unlink(cacheKey); | ||
| } catch (error) { | ||
| console.warn(`Redis del failed for key ${key}:`, error); | ||
| console.warn(`Redis unlink failed for key ${cacheKey}:`, error); |
|
@GBOYEE has applied to work on this issue as part of the Stellar Wave Program's 6th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @GBOYEE to this issue. |
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.
this pr closes #837
Description
This PR introduces a robust cache‑aside invalidation mechanism for vault and analytics data, ensuring that cached entries are correctly evicted the moment underlying data changes. It also adds per‑organization namespacing to prevent cross‑tenant cache contamination.
Changes Made
Cache Library (src/lib/cache.ts)
Added optional orgId parameter to getOrSet, invalidate, and invalidatePrefix.
Implemented namespaced key format: org:${orgId}:${key}.
Switched to non‑blocking eviction using SCAN + UNLINK (Redis) for both single key and prefix invalidation.
Vault Store (src/services/vaultStore.ts)
Updated DB queries to include organization_id.
Implemented cache‑aside getVaultById with org‑scoped keys.
Added invalidation calls after every write path (create, update, cancel) to evict:
Specific vault cache (vault:${id}) and org‑lookup (vault:${id}:org).
All vault list caches for the organization (vaults: prefix).
Analytics caches (analytics: prefix) and global overall analytics.
Analytics Service (src/services/analytics.service.ts)
Added optional orgId to getOverallAnalytics and updateAnalyticsSummary.
Triggered appropriate invalidation on analytics refresh.
Validation & Types
Updated Zod schemas (src/services/vaultValidation.ts) and TypeScript interfaces (src/types/vaults.ts) to support optional orgId / organizationId.
Documentation
Added docs/cache.md detailing namespace conventions, helper functions, and invalidation triggers.
Tests
Created src/tests/cache.invalidation.test.ts covering:
Idempotent invalidate on missing keys.
Per‑organization isolation.
Prefix invalidation within a namespace.
Large‑scale prefix scans (thousands of keys) for performance and correctness.
All tests pass (npm test).