1.8 Cache Flashcards
What is caching?
Caching improves page load times and reduces the load on servers and databases.
What does the dispatcher do in caching?
The dispatcher looks up if the request has been made before and returns the previous result.
How do databases benefit from caching?
Databases benefit from a uniform distribution of reads and writes across partitions.
What can cause bottlenecks in database performance?
Popular items can skew distribution, causing bottlenecks.
What is client caching?
Caches located on the client side (OS or browser), server side, or in a distinct cache layer.
What is CDN caching?
CDNs are considered a type of cache.
What is web server caching?
Reverse proxies and caches like Varnish can serve static and dynamic content directly.
What is database caching?
Databases usually include some level of caching in a default configuration optimized for generic use cases.
What is application caching?
In-memory caches like Memcached and Redis are key-value stores between the application and data storage.
What is a characteristic of in-memory caches?
Data held in RAM is much faster than data stored on disk.
What is cache invalidation?
Cache invalidation algorithms like least recently used (LRU) help invalidate ‘cold’ entries and keep ‘hot’ data in RAM.
What additional features does Redis have?
- Persistence option
- Built-in data structures such as sorted sets and lists
What are the two general categories of caching levels?
- Database queries
- Objects
What are some suggestions of what to cache?
- User sessions
- Fully rendered web pages
- Activity streams
- User graph data
What is cache-aside?
The application is responsible for reading and writing from storage, resulting in a cache miss that loads entry from the database.
What is a disadvantage of cache-aside?
Each cache miss results in three trips, causing a noticeable delay.
What is write-through caching?
The application uses the cache as the main data store, reading and writing data to it, while the cache manages the database.
What is a disadvantage of write-through?
When a new node is created due to failure or scaling, it will not cache entries until the entry is updated in the database.
What is write-behind (write-back)?
The application adds/updates entry in the cache and asynchronously writes to the data store.
What is a disadvantage of write-behind?
There could be data loss if the cache goes down before its contents hit the data store.
What does refresh-ahead caching do?
It automatically refreshes recently accessed cache entries prior to expiration.
What is a disadvantage of refresh-ahead?
Not accurately predicting needed items can lead to reduced performance.
What is a key challenge in caching?
Maintaining consistency between caches and the database through cache invalidation.