My applet currently accesses a url and prints the contents at that url. The problem is that url is fixed, but that url renders something different depending on the website's state. My applet will print a cached version of the contents at the url instead of actually retrieving the new 开发者_开发技巧one. I don't want the user to have to restart their browser just to get this applet to work properly and the separate_jvm tag only helps if the user refreshes the page. If I manually go into the java console and clear the classloader cache that seems to make it work.
Pretty much I want to be able to programmatically clear a JVM's cache.
After careful searching I haven not been able to find a solution, but, I was able to remember of the classic timestamp solution. If I append the timestamp to the url, even if it's not used, it will never have a cache problem.
What you need to do is set the HTTP 1.1 Cache-Control request header to no-cache. How you do that depends on the library you are using. If you are using the Apache HTTP Client, take a look at HttpRequest.setHeader(). Changing the timestamp works, but tends to clog caches with stuff that can't be reused.
精彩评论