Report Schema Cache
Component Detail
Description
In-memory and optional local-storage cache for org-specific report field schemas. Reduces Supabase round-trips when the user opens multiple reports within the same session. Implements TTL-based invalidation to pick up schema config changes.
report-schema-cache
Summaries
The Report Schema Cache is a performance optimization component that makes the app feel fast and responsive even when users are opening multiple reports across the same working session. By avoiding repeated round-trips to the cloud database to fetch the same field configuration data, it reduces latency and lowers database query costs at scale. For organizations with large field teams opening many reports daily, this translates directly into a smoother user experience and reduced infrastructure spend. The time-based invalidation mechanism ensures that when administrators update report configurations, those changes are automatically picked up without requiring users to log out and back in, keeping the operational workflow uninterrupted and the data presented always reasonably current.
This is a low-complexity, mobile-only infrastructure component with no external dependencies, making it an isolated and self-contained deliverable. Development scope is well-bounded: implement an in-memory store keyed by org ID, add optional localStorage persistence for cross-session durability, and wire in TTL-based expiry logic using the `isExpired(orgId)` check before serving cached values. Testing should cover cache hits, misses, TTL expiry, manual invalidation, and the `clear()` path used on logout. The primary scheduling risk is agreeing on the correct TTL value with product stakeholders — too short reduces the caching benefit, too long means schema changes reach users slowly.
This decision should be documented as a configurable constant rather than a hardcoded value to allow easy tuning post-launch without a code change.
Report Schema Cache is a client-side caching layer for `report-field-schema` objects, keyed by `orgId`, running exclusively in the mobile execution context. The core data structure is a plain in-memory `Map
The `invalidate(orgId)` method should remove both the in-memory entry and the localStorage key. Ensure `clear()` flushes both stores and is called on user logout to prevent cross-user data leakage. TTL should be a module-level constant (e.g., `const SCHEMA_TTL_MS = 5 * 60 * 1000`) for easy configuration.
Responsibilities
- Store parsed field schemas keyed by org ID
- Return cached schema if TTL has not expired
- Invalidate and evict stale cache entries
Interfaces
get(orgId)
set(orgId, schema)
invalidate(orgId)
clear()
isExpired(orgId)
Relationships
Related Data Entities (1)
Data entities managed by this component