Skip to content
NotesHTTP CachingVerifyPDF

HTTP Caching

Fundamentals

  1. What is HTTP caching?

    HTTP caching is a mechanism that stores previously retrieved resources so they can be reused for subsequent requests.

    Benefits:

    • Faster response times
    • Reduced server load
    • Reduced network traffic
    • Improved application performance
  2. How does HTTP caching work?

    HTTP caching uses response headers to determine how resources should be stored, reused and validated.

    The primary caching headers are:

    • Cache-Control
    • Expires
    • ETag

Types of Caching

  1. What are the different types of caching?

    Type Description
    Client-side Stores resources on the user’s device.
    Server-side Stores reusable resources on the server.
    Shared Allows multiple components or users to benefit from a common cache.

HTTP Caching Headers

  1. What is Cache-Control?

    The Cache-Control header defines caching rules for HTTP requests and responses.

    Directive Description
    max-age Specifies how long a response remains fresh.
    no-cache Requires validation before reusing a cached response.
    no-store Prevents the response from being stored.
    must-revalidate Requires validation before reusing a stale response.
  2. What is the Expires header?

    The Expires header specifies a date and time after which a cached response becomes stale.

  3. What is an ETag?

    An Entity Tag (ETag) identifies a particular version of a resource. It allows clients to validate cached responses without unnecessarily downloading the resource again.

Caching Strategies

  1. What are the different caching strategies?

    Freshness-based caching

    Resources are reused for a specified period before becoming stale.

    Validation-based caching

    The client checks with the server whether its cached resource is still valid.

    Fallback-based caching

    A default or alternative resource is served when the requested cached resource is unavailable.

Performance Optimization

  1. How can caching performance be improved?

    • Consider resource sizes and cache storage capacity.
    • Avoid unnecessary cache evictions.
    • Use Content Delivery Networks (CDNs) to serve resources closer to users.
    • Select appropriate caching headers and expiration policies.

Reference

HTTP Caching by Code with Sloba (codewithsloba.com).