A cache is a high-speed storage layer that holds copies of frequently accessed data. By serving content from the cache instead of recomputing or re-fetching it, caches dramatically improve performance, reduce server load and lower latency.
Types of Cache in Web Development
- Browser Cache — The user's browser stores static assets (images, CSS, JS) locally. Controlled by HTTP headers like
Cache-ControlandExpires. - CDN Cache — Content Delivery Network edge servers cache copies of your content globally.
- Server-Side Cache — The web server or application caches rendered HTML pages or database query results. Examples: Redis, Memcached, Varnish.
- Application Cache — In-memory caching within the application code (e.g. ASP.NET
IMemoryCache).
Cache-Control Header
Cache-Control: public, max-age=86400
max-age— Seconds the response can be cached.public— Can be cached by CDNs and shared caches.private— Only the browser may cache it (not CDN).no-cache— Must revalidate with the server before serving from cache.no-store— Do not cache at all.