Skip to content

Commit 2438d9f

Browse files
Updates cache ttl status codes doc (#19908)
1 parent 3bd7c03 commit 2438d9f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/content/docs/cache/how-to/configure-cache-status-code.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,16 @@ Provide a JSON object containing status codes and their corresponding TTLs. Each
8484
## Set cache TTL by response status via a Cloudflare Worker
8585

8686
The **cacheTtlByStatus** option is a version of the **cacheTtl** feature that designates a cache TTL for a request’s response status code (for example, `{ "200-299": 86400, 404: 1, "500-599": 0 }`).
87+
88+
## TTL handling for 304 and 200 status codes
89+
90+
1. If a TTL is not explicitly set for status code `304`, we automatically set it to match the TTL of status code `200` (if the user has defined one for `200`).
91+
92+
2. If a user explicitly sets a different TTL for `304` than for `200`, the following behavior will occur:
93+
94+
- When a `200` response is received, the asset is cached with the TTL specified for status `200`.
95+
- Once the asset expires and we revalidate with the origin, if the origin returns a `304`, the cache TTL is updated to the value set for `304`.
96+
97+
For example, if a user specifies a TTL of one hour for status `200` and 0 seconds (cache and always revalidate) for status `304`, the asset will be cached for 1 hour. After it expires, we revalidate with the origin. If the origin returns a `304`, each subsequent request will trigger revalidation. If the origin continues to return `304`, this cycle will persist.
98+
99+
This behavior is likely undesirable unless the user has a specific use case. Therefore, users should ensure that the TTL for `304` matches the TTL for `200` unless they intentionally require this behavior.

0 commit comments

Comments
 (0)