I'm trying to control the caching of resources from my server and I have verified that putting the following headers on my HTTP responses causes the browser to cache resources as expected.
Cache-Control: must-revalidate, max-age=30
Last-Modified: Mon May 19 11:21:05 GMT 2014
Expires: Mon May 19 11:51:05 GMT 2014
When the resource in the browser cache has expired the next GET on that resource from that particular client contains then a "If-Modified-Since" header is added to the GET request which makes it to the origin server.
Especially in a Java webapp context what is a good way to handle the determination of whether the resource has changed on the server-side when it gets these conditional GET requests so it can decide whether to return a 304 Not Modified or 200 OK response?
I have a few ideas but they are all custom solutions that seem like re-inventing the wheel to me:
Just have some custom query that checks the resource last modified date. (This is the most obvious way to do it)
Have a cache on the server that is independently kept in-sync with the resource update state so that the server can do a very quick check for resource modification, perhaps using a DB table listener from Spring Framework (this would be more efficient than having to do a query for each client each time, however, it is more complex to implement)