缓存在快速层(通常在内存中)存储频繁访问的数据,这样可以快速检索,无需重新计算或从较慢的源重新获取。它是改进性能和可扩展性最重要的技术之一。
缓存的作用
text
CACHING stores copies of data in a FAST location for quick repeated access:
→ instead of recomputing or re-fetching from a slow source (database, API, computation),
serve from the fast cache
→ DRAMATICALLY faster (cache hit) + REDUCES load on the slow backend
→ trades some staleness/complexity for big performance and scalability gains.
缓存的使用位置(分层)
text
BROWSER / CLIENT cache → cache on the user's device
CDN → cache static content at edge locations near users
APPLICATION cache (e.g. Redis/Memcached) → cache DB query results, computed data, sessions
DATABASE cache → query/result caching
→ caching can happen at MULTIPLE layers (defense in depth for performance)
