New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add caching #129

hadley opened this Issue Aug 12, 2014 · 0 comments


None yet
1 participant

hadley commented Aug 12, 2014

A resource is cacheable if all of the following are true:

  1. Status code was 200, 203, 300, 301, 410 (ignore 206, partial response
    for now).
  2. Method is GET or HEAD. Any other method (PUT, POST, DELETE) invalids the
    cache for that url.
  3. It has one of expires, cache-control/max-age, last-modified or etag,
    and it does not have cache-control/no-cache or cache-control/no-store.
    If present, expires must be in the future.

There are two ways to retrieve from the cache:

  1. If header includes Expires (absolute) or max-age directive
    Cache-Control (delta relative to date served), then can
    re-serve to future requests (if both specified, prefer max-age).
  2. Possibly stale entry needs to be validated with server. Send additional
    If-Modified-Since (from Last-Modified) and If-None-Match
    (from ETag). If valid, returns 304, otherwise returns full request.

New functions need:

  • parse_http_date()
  • parse_cache_control()
  • response_cacheable()
  • response_expiry() - using both expires and cache-control headers.
    Possibly cache in request object.
  • response_update() - checks if a response is still valid using by
    response_expiry() and a conditional response as necessary. Constructs
    new response if needed.
  • response_cache_info() - given a request extract all caching related information
    and show in a convenient way for debugging.

Useful links:


  • Heroku
  • Sets a Cache-Control header for n seconds.
    Returns 200 unless an If-Modified-Since or If-None-Match header is provided,
    when it returns a 304.

hadley added a commit that referenced this issue Aug 23, 2014

hadley added a commit that referenced this issue Aug 23, 2014

hadley added a commit that referenced this issue Aug 23, 2014

@hadley hadley closed this in f10e957 Aug 24, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment