Stale cache response without background revalidation in HttpClient Cache plugin
0 reputation · 07 Aug 2020, 00:33 UTC
Cache-Control Semantics in Ktor HttpClient
The Ktor HttpClient Cache plugin manages response persistence based on standard Cache-Control headers. However, there is uncertainty regarding the implementation of RFC 7234 extensions, specifically stale-while-revalidate.
When a cached response exceeds its max-age but falls within a stale-while-revalidate window, the expected behavior is for the client to serve the stale content immediately while triggering an asynchronous background request to refresh the cache. In Ktor 2.x and 3.x, it appears the default plugin may serve stale entries without initiating this automatic background refresh.
This creates a gap in operational behavior where the client relies on manual conditional requests (e.g., If-None-Match) to ensure freshness, rather than leveraging the automated revalidation logic defined in the server's cache headers.
Technical Questions
- Does the Ktor HttpClient Cache plugin natively support the
stale-while-revalidatedirective for background refreshing? - If not supported, is there a documented mechanism to extend
CacheStorageto implement asynchronous revalidation?