Bird
0
0

Consider this pseudo-code for event-based cache invalidation:

medium📝 Predict Output Q13 of 15
Rest API - Caching Strategies
Consider this pseudo-code for event-based cache invalidation:
if (dataChangedEvent) {
  invalidateCache(key);
}
return getCachedData(key);
What will happen if dataChangedEvent is true?
ACache is invalidated and fresh data is fetched next time
BCache remains unchanged and stale data is returned
CCache is updated without invalidation
DAn error occurs because cache cannot be invalidated
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the condition

    If dataChangedEvent is true, invalidateCache(key) runs, removing cached data.
  2. Step 2: Understand cache behavior after invalidation

    After invalidation, next data fetch will get fresh data, not stale cache.
  3. Final Answer:

    Cache is invalidated and fresh data is fetched next time -> Option A
  4. Quick Check:

    Event triggers invalidation = fresh data next fetch [OK]
Quick Trick: Event true means cache cleared for fresh data [OK]
Common Mistakes:
MISTAKES
  • Assuming cache stays after invalidation
  • Thinking cache updates automatically
  • Believing invalidation causes errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes