Caching stores frequently accessed data closer to where it's needed, reducing the time and resources required to fetch it again.
Types of caching
Browser caching
- Stores files locally on user's device
- Controlled via Cache-Control headers
- Reduces server requests for repeat visits
Server caching
- Application-level caching (e.g., database queries)
- Full-page caching
- Object caching (Redis, Memcached)
CDN caching
- Edge servers store content globally
- Reduces origin server load
- Serves users from nearby locations
Cache-Control headers
Cache-Control: max-age=31536000, immutable
Cache-Control: no-cache
Cache-Control: private, max-age=3600
Caching strategies
- Cache-first: Serve from cache, update in background
- Network-first: Try network, fall back to cache
- Stale-while-revalidate: Serve cache while updating
Caching and performance
Effective caching improves:
- TTFB for returning visitors
- Reduced server load
- Lower bandwidth usage
- Better user experience
Related Terms
Content Delivery Network (CDN)
A geographically distributed network of servers that work together to provide fast delivery of internet content by serving it from locations closer to users.
Latency
The time delay between a user action and the system's response, often referring to network delay in web performance.
Server Response Time
The time it takes for a server to respond to a request from a browser, measured from request initiation to receiving the first byte of response.
Time to First Byte (TTFB)
A performance metric that measures the time between the request for a resource and when the first byte of a response begins to arrive.