| Location/Level | Browser (Client), Edge Servers (CDN) | Edge Servers (Globally distributed) | Browser (Client-side via Service Worker script) | Server (Before application logic) | Application Server (In-memory, File system, External Store) | Database Server or External Cache Layer (e.g., Redis/Memcached) |
| What it Caches | Static assets (CSS, JS, Images, Fonts), HTML, API Responses | Static assets, Sometimes dynamic content (configured) | Any fetched resource (HTML, assets, API calls) | Full/partial HTTP Responses (HTML, JSON) | Data objects, API call results, HTML fragments, Computation results | Query results, Data blocks, Prepared statements |
| Mechanism | HTTP Headers (Cache-Control, Expires, ETag, Last-Modified) | Pulls from origin, Caches on edge servers, HTTP headers respected | Intercepts network requests, Uses Cache API | Key-value lookup based on URL, headers, query params | Key-value store lookup (in-memory, external), Object serialization | Internal DB mechanisms (buffer pool, query cache), External key-value store |
| Control/Management | Server (via response headers), Browser (user clearing) | CDN Provider config, Origin Server headers (config) | Developer (via Service Worker JS code) | Server Admin/Developer (config) | Developer (via application code) | DBA, Developer (query structure) |
| Invalidation Methods | Expiration time, Validation (ETag, Last-Modified), Cache-busting URLs, User clear | Expiration time, Manual purge, Origin validation (less common) | Code logic (update/replace SW, manual cache deletion) | Time-based expiration, Manual purge, Cache invalidation rules | Time-based expiration, Manual invalidation (code), Cache-aside/write-through logic | Data changes (DB triggers), Configuration settings, Manual flush |
| Pros | Reduces server load, Faster repeat visits, Standardized | Global distribution, Reduced latency, Handles traffic spikes, Reduces origin load | Offline support, Fine-grained control, Faster loads | Reduces load on application servers, Faster responses, Scalable | Reduces DB/API calls, Highly customizable, Fast access | Speeds up database reads, Reduces disk I/O |
| Cons | Can be complex to configure correctly, Staleness issues | Cost, Configuration complexity, Potential for staleness | Requires JS knowledge, Debugging can be tricky, Initial load might not benefit | Complex config/management, Staleness if not invalidated | Increased application complexity, Memory consumption, Consistency issues (especially distributed) | Configuration complexity, Potential for stale query cache (less common in modern DBs), Cache invalidation complexity |
| Use Cases | Caching static assets, General website performance | Global content delivery, High-traffic sites, Static assets | PWAs, Offline-first experiences, Complex caching needs | Caching API responses, Full page caching, Backend protection | Caching frequently accessed data, Reducing repetitive calculations, Caching external API results | High-read low-write scenarios, Reducing load on database server |