-
-
Notifications
You must be signed in to change notification settings - Fork 669
Description
Bug Description
Although async behavior was added in #4492 (thank you for that 👍 ), the CacheHandler does not know what to do with 304 not modified
responses and ignores them. This causes the next request to be hit the backend again, instead of the updated cache.
See interceptor/cache.js#259 and handler/cache-handler.js#254 (NOT_UNDERSTOOD_STATUS_CODES
includes 304).
Reproducible By
- Configure undici with cache interceptor.
- Have a backend that replies with a 304 when
if-none-match
and/orif-modified-since
headers are present. The reply must include cache headers, e.g.max-age=5, stale-while-revalidate=3600
. - Perform a request with empty cache: see 200 OK and cache entry is inserted.
- Wait 5s (so response is stale) and perform a new request.
- Cache handler is responding immediately with stale data (good!) and starts revalidation.
- Revalidation is being answered by backend with
304 not modified
. - Perform a new request
- See request hitting backend server, not using cache (I think). Backend server replies with 200 OK again and it is being cached again.
In my Varnish logs I see requests answered with 304 and upon next request requested again and answered with 200 (which implies this is not a revalidation request).
Expected Behavior
When revalidation request is being answered with a 304 not modified
and cache headers, we expect the cache expiry to be updated for this request.
Additional context
I think that we should use the CacheRevalidationHandler in the cache interceptor (instead of the CacheHandler) and update the cache upon succesful revalidation. Similar to what is happening when we're within the stale-if-error
period, see interceptor/cache.js#325.