jsouphttp-caching

Does jsoup.connect().get() return cached Document?


I use jsoup and following code to get the HTML content of a website Document doc = Jsoup.connect(this.getUrl()).get();.

Does I get a cached version of the website? Is it possible to request a non-cached version? I knew I could set a header request. Something like:

header("Cache-control", "no-cache");  
header("Cache-store", "no-store");

But I’m not sure if that works. I just knew that these tags are used for the client browser.

It would be awesome if someone could clarify. Greetings.


Solution

  • Any headers that you correctly (HTTP spec) specify will be sent to target host via java.net.URLConnection.addRequestProperty(String, String). You should get a cached version of the page if server supports this header, end-to-end. jSoup just supplies the headers as the request it made and when I looked through the source, it does not make any explicit effort to cache off the response content.