Compare Time-Based expiration and Explicit Invalidation. Which is preferred for strict consistency?
Python interview question for Advanced practice.
Answer
Time-Based expiration (TTL) removes data after a fixed duration; it is simple but risks serving stale data. Explicit Invalidation involves the application removing or updating the cache entry as soon as the source data changes. Explicit Invalidation is generally preferred for strict consistency because it ensures the cache is never out of sync with the primary database, though it increases application complexity.
Explanation
Stale data remains one of the 'two hard things' in computer science alongside naming things.