Skip to content

Comments

fix(cache): add TTL and invalidation to sessionStorage cache#300

Open
GziXnine wants to merge 2 commits intochicagopcdc:devfrom
GziXnine:fix/session-cache-invalidation
Open

fix(cache): add TTL and invalidation to sessionStorage cache#300
GziXnine wants to merge 2 commits intochicagopcdc:devfrom
GziXnine:fix/session-cache-invalidation

Conversation

@GziXnine
Copy link

@GziXnine GziXnine commented Feb 7, 2026

Summary

getStudies(), getEligibilityCriteria(), and getMatchConditions() cached responses in sessionStorage with no expiry, no TTL, and no cache invalidation mechanism. Once cached, stale data persisted for the entire browser session.

Problem

  • No cache-busting on re-fetch: fetchAll() and "Try Again" flows returned stale cached data instead of making network requests.
  • No TTL: Data lived until the tab was closed. Clinicians may keep tabs open for hours.
  • No invalidation after admin publish: Published eligibility criteria changes were invisible to users with open tabs.

Impact

Clinicians making trial-matching decisions based on stale data. Admins confused when published changes are not reflected.

Fix

  1. TTL in readCache/writeCache: Cache entries now include a timestamp. readCache() checks against a 5-minute default TTL and evicts expired entries.
  2. clearGearboxCache() utility: Removes all cached gearbox keys from sessionStorage.
  3. Cache clearing in fetchAll(): useGearboxData.fetchAll() calls clearGearboxCache() before re-fetching, ensuring "Try Again" and re-fetch flows always get fresh data.
  4. Backward compatible: Legacy cache entries without timestamps are handled gracefully.

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

  • All existing tests pass
  • Changes span src/api/utils.ts and src/hooks/useGearboxData.ts

grugna and others added 2 commits November 11, 2025 13:12
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.
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.

2 participants