Suitable Cache Use Case
Which scenario is best suited for using a cache to store database query results?
- Querying frequently accessed but rarely changing data
- Querying data that changes every few milliseconds
- Running write-heavy transactions
- Backing up the entire database regularly
- Using cache for handling user authentication tokens
Cache Strategy Choice
Given that your user profile data changes occasionally but is queried often, which caching strategy is most appropriate?
- Read-through caching
- Write-back caching
- Cache-busting
- No caching at all
- Full-database replication
Cache Expiration Policy
What is the main reason to set an expiration time (TTL) on cached query results?
- To ensure stale data doesn't remain in cache indefinitely
- To save memory on the disk
- To improve the syntax of SQL queries
- To allow database normalization
- To prevent SQL injection attacks
Cache Invalidation
When should you invalidate/evict a cached item for a SELECT query on a products table?
- Whenever the corresponding product is updated or deleted
- At a random time
- Only when a user logs out
- After every database connection
- After every server restart regardless of data
Query Result Uniqueness
Why is it important to include query parameters (such as filters or pagination) in your cache key?
- So each unique query result is properly cached and retrievable
- To increase memory usage unnecessarily
- Because SQL requires unique cache keys
- To allow for LRU cache eviction policy
- To enable transaction rollback
Code Snippet Analysis
Given the following code snippet, what is the main issue?nncache.set('users', results)n# Later...ncached = cache.get('users?name=alice')nn
- The cache key does not include the query parameters, causing potential data mismatch
- The cache object is not thread-safe
- No cache timeout has been set
- The code exposes cache to SQL injection
- Cache should use read-through, not manual set/get
Cache Write Strategy
Which of the following describes write-through caching in the context of a database?
- Every write updates both the cache and the database immediately
- Every write only updates the cache, not the database
- Writes update the database but not the cache
- Cache updates are deferred until eviction
- Data is always written asynchronously to the cache
Distributed Cache Consistency
In a distributed cache system, what is a common challenge when caching query results?
- Keeping cached data consistent across multiple nodes
- Not enough RAM on a single server
- Needing to normalize database tables
- Ensuring database schema migrations occur
- Caching only works with SQL databases
Avoiding Cache Stampede
What is a ‘cache stampede’ in database caching strategies, and how can it be avoided?
- When many clients simultaneously try to refresh an expired cache entry; use locking or request coalescing to prevent it
- A typo in the cache key format; you fix it by spellchecking
- When cache servers run out of storage space; use SSD caching
- When a network outage deletes all cache data; add more cables
- When cache TTLs are too long; reduce TTL duration
Selecting a Cache When Data is Volatile
If a dataset changes very frequently and consistency is critical, what is the most appropriate caching strategy for query results?
- Avoid caching or use a very short TTL
- Cache with a long expiration time
- Never invalidate cache entries
- Store all dataset copies in cache permanently
- Only cache on the client-side