fix(cache): add TTL and invalidation to sessionStorage cache#300
Open
GziXnine wants to merge 2 commits intochicagopcdc:devfrom
Open
fix(cache): add TTL and invalidation to sessionStorage cache#300GziXnine wants to merge 2 commits intochicagopcdc:devfrom
GziXnine wants to merge 2 commits intochicagopcdc:devfrom
Conversation
The sessionStorage cache for studies, eligibility criteria, and match conditions had no expiry, no TTL, and no invalidation mechanism. Once cached, stale data persisted for the entire browser session — even after admin publishes or backend updates. Changes: - Add timestamp-based TTL (5 min default) to readCache/writeCache in api/utils.ts - Add clearGearboxCache() utility to remove all cached gearbox keys - Call clearGearboxCache() at the start of fetchAll() in useGearboxData so re-fetches (including 'Try Again' flows) always get fresh data - Handle legacy cache entries gracefully (backward compatible) This ensures clinicians see up-to-date trial data and admins see published changes reflected without requiring a hard refresh.
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.
Summary
getStudies(),getEligibilityCriteria(), andgetMatchConditions()cached responses insessionStoragewith no expiry, no TTL, and no cache invalidation mechanism. Once cached, stale data persisted for the entire browser session.Problem
fetchAll()and "Try Again" flows returned stale cached data instead of making network requests.Impact
Clinicians making trial-matching decisions based on stale data. Admins confused when published changes are not reflected.
Fix
readCache/writeCache: Cache entries now include atimestamp.readCache()checks against a 5-minute default TTL and evicts expired entries.clearGearboxCache()utility: Removes all cached gearbox keys fromsessionStorage.fetchAll():useGearboxData.fetchAll()callsclearGearboxCache()before re-fetching, ensuring "Try Again" and re-fetch flows always get fresh data.Note: The existing cache key
'gearbox:eligiblity-criteria'has a typo (missing second 'i'). This fix preserves the existing key to maintain compatibility.Fixes #295
Testing
src/api/utils.tsandsrc/hooks/useGearboxData.ts