I’ve implemented a system for cache url into the filesystem (Android java) working this way:
-
Given an url the file is downloaded into /one_folder/hash(url).file
-
The next petition for that url first checks if the file exists. If yes the file is returned else the download is repeated.
The problem is that if no extra logic is implemented and the file at the url is changed, it is never detected (cause the cache always success).
How can I improve that? Is there a better system that assign a expiration date to the cached files and redownload it if expired?
Thanks
When you download the file check the HTTP headers. In there you will probably find cache rules, content expire dates etc.
Or you could issue a HEAD request instead of a GET request and only get the http headers (not the content/file) and compare last modified or file size (content length).