LWCIntermediatecachingimperativeperformance
Cache imperative Apex results in LWC with staleness tolerance policy
Real World Scenario
Dashboard LWC calls expensive Apex aggregate on every tab switch reloading same 30-day metrics unnecessarily.
Expected Answer
• Module-level Map cache keyed by filter params plus recordId
• TTL timestamp invalidate cache after business-defined interval
• Force refresh button bypasses cache for user-initiated reload
• Clear cache on recordId or filter @api change in setter
• Do not cache user-specific PII in module cache on shared machines
• Prefer wire cacheable=true Apex when data is read-only
• Display stale indicator when showing cached data during background refresh
Follow-Up Questions & Answers
Click to expand — each follow-up includes a direct, interview-ready answer
Main difference: use case and scale. Module-level Map cache keyed by filter params plus recordId. TTL timestamp invalidate cache after business-defined interval. Pick based on your integration pattern and team capability. Client cache needs explicit TTL and invalidation—unbounded module cache hides stale business data. Balance speed of delivery with maintainability.
Architect Perspective
Client cache needs explicit TTL and invalidation—unbounded module cache hides stale business data.