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.

Unexpected automatic (local) caching of requests without query strings

See original GitHub issue

First of all, I’m not sure if this is really a bug or intentional behavior, but here’s a test anyway: https://gist.github.com/apottere/93e89c7645c1b2e9f97402b10507d574

We decided to switch from Apache HC to OkHttpClient in our rest APIs to take advantage of better pooling/connection re-use. We’re using the Spring Boot starter to create a RestTemplate with which we call backend REST APIs (java -> java). Everything worked great out-of-the-box, until we noticed that one of our services wasn’t getting called at all.

We did some digging and realized that it’s the only service that uses ETag and Last-Modified to support caching of requests with conditional gets, but it does not set any other cache-control headers. We found that our clients were no longer sending more than one request to the API because of this block of code.

The provided test shows that a request for a URL - given a previous response for that url with ETag and Last-Moidified headers returned - will hit that block of code, and one of two things will happen:

  1. If the request has no query parameters, it will return the cached response without contacting the server
  2. If the request has at least one query parameter, it will send a request to the server with a conditional get.

With respect to the comment on the offending block of code, it could be reasonable that a browser cache pages without query parameters for some time if they’ve sent a Last-Modified header, but it seems completely unexpected for that to be default functionality in a REST client.

Would it be possible to make this behavior opt-in instead of opt-out?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
yschimkecommented, Mar 29, 2020

Won’t fix.

0reactions
apotterecommented, Feb 15, 2018

AFAICT that’s the only section of the http caching RFC that uses the language MAY, so it doesn’t seem too unreasonable to want a toggle for turning that functionality on and off.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Caching Everything While Ignoring Query Strings
Enterprise customers can cache any type of static content, like HTML files, and ignore query strings in the resource URL by using Custom......
Read more >
Automatic persisted queries - Apollo GraphQL Docs
A persisted query is a query string that's cached on the server side, along with its unique identifier (always its SHA-256 hash).
Read more >
Status codes in HTTP
The purpose of this feature is to allow efficient updates of local cache information (including relevant metainformation) without requiring the overhead of ...
Read more >
Customize cache keys | Cloud CDN
Updating cache keys to re-add protocol, host, and query string · In the Google Cloud console, go to the Cloud CDN page. ·...
Read more >
7 Managing Performance Tuning and Query Caching
If the cache entries are not purged when the data in the underlying databases changes, then queries can potentially return results that are...
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