Bird
0
0

Given this pseudo-code for event-driven cache invalidation:

medium📝 Predict Output Q4 of 15
Rest API - Caching Strategies
Given this pseudo-code for event-driven cache invalidation:
if (updateEvent) {
  cache.invalidate('item42');
}
return cache.get('item42');

What will be returned if updateEvent is true?
AThe stale cached data for 'item42'
BAn error due to invalidation failure
CA cache miss leading to fresh data retrieval
DThe old data without invalidation
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the code flow

    If updateEvent is true, cache.invalidate('item42') is called, removing the cached entry.
  2. Step 2: Understand cache.get after invalidation

    Since the cache entry is invalidated, cache.get('item42') results in a cache miss, triggering fresh data retrieval.
  3. Final Answer:

    A cache miss leading to fresh data retrieval -> Option C
  4. Quick Check:

    Invalidation causes cache miss, so fresh data returned [OK]
Quick Trick: Invalidation causes cache miss, triggers fresh fetch [OK]
Common Mistakes:
MISTAKES
  • Assuming invalidation returns stale data
  • Thinking invalidation causes errors
  • Ignoring cache miss after invalidation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes