Take the 2-minute tour ×

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.

share|improve this question
So what you're looking for is a pretty complete http proxy in java to be embedded into an application? I agree there should be some thing like that, but I wouldn't expect it in general purpose libraries. But looking for a specialized lib might be a good idea. –  Sir RotN Nov 16 '12 at 16:01
For starters, I would be content with something that accepts local files :-/ Or a cache that has a "is still valid" method which I can overwrite. –  Aaron Digulla Nov 16 '12 at 16:19
add comment

2 Answers

up vote 1 down vote accepted

You may use HttpClient Cache.


share|improve this answer
add comment

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

If it fails reload the file.

share|improve this answer
The HTTP/1.1 standard was introduced 1999. I hope that after 13 years, there is a more simple way to do this than reading the standard and writing a whole lot of code :-) –  Aaron Digulla Nov 16 '12 at 14:56
@AaronDigulla I have changed my answer :) i guess a far more older approach :) –  sheldonCooper Nov 16 '12 at 15:10
add comment

Your Answer


