Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What determines request equivalence for HTTP caching?

Tags:

http

caching

I feel like this has to be easy to Google, but I can't find it: from the perspective of an HTTP cache, what determines if two requests are equivalent?

I imagine one ingredient is that that their URLs need to be identical; for example, rearranging (but not changing) query string parameters seems to cause a cache miss. Presumably they need to have the same Accept header. What else determines if a request can be served from cache?

like image 653
Alan O'Donnell Avatar asked Jun 21 '15 23:06

Alan O'Donnell


People also ask

What are the three states of HTTP caching?

HTTP options The Hypertext Transfer Protocol (HTTP) defines three basic mechanisms for controlling caches: freshness, validation, and invalidation. This is specified in the header of HTTP response messages from the server.

How does HTTP support caching?

HTTP caching occurs when the browser stores local copies of web resources for faster retrieval the next time the resource is required. As your application serves resources it can attach cache headers to the response specifying the desired cache behavior.

Which HTTP request can be cached?

The POST response body can only be cached for subsequent GET requests to the same resource. Set the Location or Content-Location header in the POST response to communicate which resource the body represents. So the only technically valid way to cache a POST request, is for subsequent GETs to the same resource.

Is cache-control for request or response?

The Cache-Control HTTP header field holds directives (instructions) — in both requests and responses — that control caching in browsers and shared caches (e.g. Proxies, CDNs).


1 Answers

This is mostly described in this RFC: https://www.rfc-editor.org/rfc/rfc7234#section-4

Summary:

  • The method
  • The full uri
  • Caching-related headers in response influence whether something got stored.
  • Any request headers that appeared in the list of the Vary response header.

It also matters whether you are caching for a specific user (for example a browser), or many users (for example a proxy).

like image 175
Evert Avatar answered Jan 03 '23 14:01

Evert