What is Caching
Storing data for fast access
Caching — Speeding Up Data Access
Caching is a technique of storing data copies in fast-access storage to speed up subsequent requests.
Caching Types
| Type | Description | Examples | |------|-------------|----------| | In-Memory | In RAM | Redis, Memcached | | Browser | In client browser | localStorage, Cache API | | CDN | On edge servers | Cloudflare, CloudFront | | Database | DB query cache | Query cache, Materialized views |
Caching Strategies
- Cache-Aside — application manages cache
- Read-Through — cache loads data automatically
- Write-Through — write to cache and DB simultaneously
- Write-Behind — asynchronous write to DB
Invalidation Policies
- TTL — Time To Live
- LRU — Least Recently Used eviction
- LFU — Least Frequently Used eviction
- Event-based — on data change event
Efficiency Metrics
- Hit Rate — cache hit percentage (target: >90%)
- Latency — cache response time (<1ms for in-memory)