Must-revalidate does not revalidate
See original GitHub issueI have an i ssue where OkHttp does not revalidate requests. (3.10.0) If the cache-control says “must-revalidate”, the request should be revalidated.
In that case, the CacheStrategy
should return a not null network request:
@Test
fun shouldRevalidate() {
val nowMillis = 1527845183942 // =Fri Jun 01 2018 09:26:23
val request = Request.Builder()
.method("GET", null)
.url("https://my.url.com/v1/item/d002fbef-7061-4d92-9958-7b128cf85855")
.build()
val handshake = Handshake.get(
TlsVersion.TLS_1_2,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, emptyList(), emptyList()
)
val cacheCandidate = Response.Builder()
.code(200)
.addHeader("date", "Fri, 01 Jun 2018 07:45:40 GMT")
.addHeader("cache-control", "private, must-revalidate")
.addHeader("last-modified", "Thu, 31 May 2018 08:04:53 GMT")
.sentRequestAtMillis(1527839142145) //=Fri Jun 01 2018 07:45:42
.receivedResponseAtMillis(1527839142295) //=Fri Jun 01 2018 07:45:42
.request(request)
.protocol(Protocol.HTTP_1_1)
.handshake(handshake)
.message("")
.build()
val cacheStrategy = CacheStrategy.Factory(nowMillis, request, cacheCandidate)
.get()
assertThat(cacheStrategy.networkRequest).isNotNull()
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Difference between no-cache and must-revalidate for Cache ...
If a response is cacheable for 10 seconds, then must-revalidate kicks in after 10 seconds, whereas no-cache implies must-revalidate after 0 ...
Read more >Cache-Control - HTTP - MDN Web Docs
The must-revalidate response directive indicates that the response can be stored in caches and can be reused while fresh. If the response ...
Read more >My browser keeps showing cached page despite sending no ...
must-revalidate : Only means that a stale cached document must be revalidated with the origin server. Implied by no-cache so has no additional ......
Read more >Staleness and revalidation - Fastly Developer Hub
IMPORTANT: If there is already a background revalidation in progress for the resource being requested, the stale object will be served but a...
Read more >cache-control: no-store, no-cache, must-revalidate
Hi there, I have been trying to verify if my page is being served from LSCWP, and apparently it is not. I get...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My understanding is that this flag means when cached and not stale, normal caching rules can be used. When cached but stale, clients and the cache can’t override the stale checks and use the cache results. is that your understanding?
One small note:
OkHttpClient.Builder().build()
without replacing an existing client isn’t doing anything.