有没有办法让小程序以编程方式清除自己的缓存?
我的小程序当前访问一个网址并打印该网址的内容。问题是 url 是固定的,但该 url 根据网站的状态呈现不同的内容。我的小程序将打印 url 中内容的缓存版本,而不是实际检索新版本。我不希望用户必须重新启动浏览器才能使该小程序正常工作,并且separate_jvm 标记仅在用户刷新页面时才有帮助。如果我手动进入 java 控制台并清除类加载器缓存,这似乎可以使其工作。
我非常希望能够以编程方式清除 JVM 的缓存。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过仔细搜索,我还没有找到解决方案,但是,我能够记住经典的时间戳解决方案。如果我将时间戳附加到 url 中,即使不使用它,也永远不会出现缓存问题。
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.
您需要做的是将 HTTP 1.1 Cache-Control 请求标头设置为 no-cache。如何执行此操作取决于您正在使用的库。如果您使用的是 Apache HTTP 客户端,请查看 HttpRequest.setHeader()。更改时间戳是可行的,但往往会因为无法重用的内容而堵塞缓存。
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.