Cache
Location of Caching
Client (Browser) Caching
Cache data in browser.
You can do it manually, store things like user info such as profile pic or email. You don't want to request that very time. Or some data for offline working or faster rendering.
There are libraries doing this automatically, such as Apollo GraphQL Client. It can cache GraphQL queries automatically, so that repetitive requests aren't made.
Server-Side Caching
Reverse Proxy can cache data.
CDN Caching
Application Caching
There are applications like Redis that cache in memory. Cache Invalidation is required. There are algorithms like LRU.
Database Caching
Databases support caching, to save time from queries.
-
Query Level Caching
- Use query hash as key to cache
- Gets complicated when query is complex, changing a single cell may affect many cache.
-
Object Level Caching primer
Types of Caching
Cache-Aside
Write-Through
Write-Begind (write-back)
Write data to database asynchronously. Good for situations that have super high frequency database write.
Refresh-Ahead
Database automatically refresh recently accessed cache prior to expiration.
- Reduced Latency
- Drawback: Have to accurately predict which items are going to be queried.