Caching content of URL

2019-07-02 07:16发布

问题:

I have a pretty simple use case: Cache the content of a URL with correct and automatic reloading when the content on the remote side changes (for example when "last modified" changes).

How can I do that in Java?

Note: I have spring, guava and commons-lang3 on the classpath but I couldn't find any support for this. Guava supports cache eviction but there is no way to implement per-access checks.

回答1:

You may use HttpClient Cache.

HttpClient Cache provides an HTTP/1.1-compliant caching layer to be used with HttpClient--the Java equivalent of a browser cache.



回答2:

You could save the checksums of the files in database and compare it with the remote side file.

If it fails reload the file.



标签: java url caching