Skip to content

Commit 9c2691d

Browse files
pi0claude
andcommitted
fix(cache): only cache GET/HEAD and never store per-user responses
- Only `GET` and `HEAD` requests read or write the handler cache; other methods and `Range` requests call the handler directly. `HEAD` uses a separate key (GET keys unchanged). - Never store responses that set cookies; `set-cookie` is only sent to the request that produced the response, and concurrent requests resolve their own response instead of sharing it. - Never store responses with `cache-control` private/no-store/no-cache and keep the handler's own `cache-control`. - Never store responses whose `vary` is `*` or names a header not in `varies` (except `accept-encoding`). - Remove a stored entry when a fresh response is no longer cacheable. - Capture `appendHeader` in the response proxy (multiple cookies). Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a676074 commit 9c2691d

8 files changed

Lines changed: 399 additions & 141 deletions

File tree

‎docs/1.guide/6.cache.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ With this example, the response will be cached for 1 hour and a stale value will
2525
All incoming request headers are dropped when handling cached responses. If you define the `varies` option, only the specified headers will be considered when caching and serving the responses.
2626
::
2727

28+
::important
29+
Only `GET` and `HEAD` requests are cached. Requests with other methods, and requests with a `Range` header, always call the handler directly.
30+
31+
Responses are not stored in the cache when they:
32+
- set a cookie (`set-cookie` header). The cookie is only sent to the request that produced the response.
33+
- have a `cache-control` header containing `private`, `no-store` or `no-cache`. The handler's `cache-control` header is preserved.
34+
- have a `vary` header that is `*` or names a request header which is not listed in `varies` (except `accept-encoding`).
35+
::
36+
37+
::warning
38+
`event.context` is shared with the incoming request. Avoid rendering request-specific data from `event.context` (such as the current user set by a middleware) in cached handlers, as it will be served to all subsequent requests.
39+
::
40+
2841
See the [options](#options) section for more details about the available options.
2942

3043
::note

0 commit comments

Comments
 (0)