Identifying Cacheable Data
Which type of data is generally the best candidate for caching to reduce database load?
- Frequently-read, rarely-changing data
- Rapidly-mutating session tokens
- Temporary user uploads
- Real-time sensor readings
- Large image files stored in the file system
Choosing Cache Granularity
Suppose your web application often displays product details. Which caching strategy is best if product data changes infrequently, but associated reviews update constantly?
- Cache product details separately from reviews
- Cache both product details and reviews together
- Cache only the reviews
- Do not cache anything
- Cache the user's search queries instead
Recognizing What NOT to Cache
Which one of these should typically NOT be cached to avoid serving outdated information?
- Highly dynamic, per-user financial transactions
- Popular static blog articles
- Data pulled from a rarely-updated configuration file
- Public product catalog pages
- Frequently-accessed error messages
Understanding Cache Invalidation
If a cached value is updated in the database, what is the recommended action for the cache?
- Invalidate or update the cached value immediately
- Wait until the cache expires naturally
- Add a new cache entry alongside the old one
- Ignore the change; caching takes priority
- Clear all cached data unrelated to the change
Cache Key Granularity
When caching user-specific dashboard data, which cache key strategy best avoids incorrect data being shown to the wrong user?
- Include the user's unique ID in the cache key
- Use a global cache key for all users
- Use the URL path as the cache key
- Base the cache key on the current date
- Ignore cache keys to simplify the design
Deciding What Computations to Cache
You have a function that performs an expensive aggregation over millions of rows. The aggregation result is requested often and is updated only once a day. How should you handle caching?
- Cache the aggregation result and invalidate it daily
- Recompute the aggregation for every request
- Do not cache and serve stale results
- Cache only for premium users
- Cache the function input parameters instead
Cache Invalidation Typo Trap
What issue might you face if you forget to invalidiate a cache entry after updating data?
- Stale data being served to users
- Increased database accuracy
- Improved real-time updates
- Faster cache build times
- Accidental removal of valid cache
Evaluating Computation Cost
When deciding whether to cache a computation, which is the most important factor?
- The cost (CPU/memory/time) of recomputing the value
- The number of lines in the function
- How many developers worked on the feature
- The name of the cache server
- The color scheme of your application
Scenario: Cached User Profile
You cache user profile pages. Which event should trigger a cache invalidation for a user's profile?
- When that user updates their profile information
- When any user logs out
- On midnight every night
- When the application deploys
- During every API call
Cache Duration Considerations
If you have data that changes infrequently, which cache strategy is generally best?
- Set a long cache expiration time
- Use no cache at all
- Set a very short cache duration
- Purge the cache every minute
- Only cache the data after it has been requested 100 times