Choosing Cache Candidates
Which type of data is generally the BEST candidate for caching?
- Frequently accessed and rarely changing data
- Highly dynamic stock price feeds
- User passwords
- Sensitive authentication tokens
- Single-use access codes
Invalidation Strategy
If a cached user's profile is updated, what is the most appropriate cache invalidation action?
- Remove only the cached entry for that user
- Purge the entire cache
- Extend the cache's expiration time
- Do nothing and rely on natural expiry
- Invalidate all caches related to the application
Cache-Aside Pattern
In the cache-aside pattern, what happens when a cache miss occurs?
- Data is loaded from the database and put in the cache
- An error is thrown to the client
- The cache is purged
- Nothing happens; empty data is returned
- All cached data is refreshed
Stale Data Scenario
Suppose a product's price changes. You are using a cache with a 10-minute TTL. When would it be MOST appropriate to invalidate the cache for that product?
- Immediately after updating the price in the database
- Exactly after 10 minutes have passed
- Only when the cache is queried next
- Every hour automatically
- Never invalidate; just let the TTL expire
Cache Consistency
Which technique helps maintain cache consistency with the underlying data store?
- Write-through caching
- Increasing cache size
- Adding random delays to cache updates
- Enhancing log verbosity
- Ignoring update operations
Identifying Overcaching
Which of the following is a symptom of overcaching?
- Users see outdated information frequently
- Database load increases significantly
- Application response time decreases
- Less memory is used on the cache server
- Cache hit ratio is extremely low
Scenario: Expiring Login Session
If login sessions are cached and can be revoked at any time, what is the best invalidation approach?
- Explicitly delete the session from the cache upon revocation
- Rely solely on automatic TTL expiration
- Extend session lifetime whenever accessed
- Invalidate all sessions whenever any session is revoked
- Cache sessions permanently
Cache Key Design
Which is the best practice when designing cache keys for user-specific data?
- Include the user's ID in the cache key
- Use only the data type as the cache key
- Use a static key for all users
- Do not use cache keys
- Randomize the cache key on each request
Lazy vs. Eager Invalidation
Which statement correctly describes lazy cache invalidation?
- Cached data is invalidated only when the data is next requested
- All cached data is invalidated at regular scheduled intervals
- Cached data is immediately invalidated upon any update
- Cached data is never invalidated
- The cache size is decreased on invalidation
Cache and Critical Real-Time Data
Why is it generally a bad idea to cache real-time sensor data?
- Real-time data changes too quickly to remain accurate if cached
- Caching real-time data always provides fresher results
- Caches cannot be used for any kind of data
- Caches automatically update themselves in real-time
- Caching uses more CPU than direct data access