question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Must-revalidate does not revalidate

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
yschimkecommented, Jun 16, 2018

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?

1reaction
yschimkecommented, Jun 3, 2018

One small note: OkHttpClient.Builder().build() without replacing an existing client isn’t doing anything.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found