Java 1.7 applet CacheEntry preventing dynamic updates
Asked Answered
C

5

3

I am migrating Java 1.6 applets to Java 1.7. One of our applets periodically hits an URL to retrieve a dynamic status value:

https://host/myapp/path/to/status

And then it updates according to the latest status value. Since upgrading to Java 1.7, my client does not retrieve the latest status value. I see entries like this in the Java console:

CacheEntry[https://host/myapp/path/to/status]: updateAvailable=true,lastModified=Wed Dec 31 17:00:00 MST 1969,length=82

It looks like the client has some cached value for that URL and isn't actually retrieving the latest dynamic value from the server.

This worked fine as a 1.6 applet, and it also works fine as a 1.7 standalone Java application. How can I disable or bypass this caching behavior when running as a 1.7 applet?

Cohn answered 19/6, 2013 at 0:29 Comment(0)
C
3

I've resolved this problem by using the following HTTP header in the server response:

Cache-Control: no-cache, no-store, no-transform

Now my Java 1.7 applet fetches the data from the server every time. Apparently Oracle changed how applets respond to these headers in Java 1.7. Previously (when we were using Java 1.6 applets), we had the following header:

Cache-Control: no-cache

and that worked in Java 1.6 but not in 1.7.

Cohn answered 28/8, 2013 at 18:28 Comment(0)
P
2

Had a similar problem with a Java applet and this fixed it:

Go to Control Panel (or System Preferences) > Java > General > Settings and then uncheck the box that says "Keep temporary files on my computer".

Precursory answered 19/6, 2013 at 0:44 Comment(2)
This did resolve the issue, but it is a less than ideal solution, because it forces our users to remember to change this setting (because keep temporary files is the default setting). And if they receive a Java update or something, perhaps the setting will be reverted to the default.Cohn
It's still a correct answer to your question and therefore the answer should be accepted.Precursory
A
0

I'm having the same problem. I tried using URLConnection.setUsesCaches(false) but that does absolutely nothing.

I had to add the following to an http config file for apache. Then it worked.

<Directory /foo>
    <FilesMatch "\.(xml)$">
        Header set Cache-Control "no-cache, no-store, no-transform"
    </FilesMatch>
</Directory>
Annikaanniken answered 5/11, 2013 at 23:42 Comment(0)
S
0

I already solved this problem that has been happening to me as well.

I add some fake arguments at the end of the URL such as date time or what ever that change every time i call the url.

for my own solution:

I genereate a date string

SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssz" );  
String today = formatter.format( new java.util.Date() );

and after that when i call the url i put the date sstring to the end of the url

new URL("http://url.to.something?fake_query_string=" + today);

with this solution, it'll fool java as a new url, so there's no any cache for this url, then java would always retrieve the data.

PS. it wouldn't be the best solution, but it saves me.

Slink answered 9/12, 2014 at 9:36 Comment(0)
C
0

For me using setUseCaches(false) alone did not work. But calling both the following methods did work:

connection.setUseCaches(false);
connection.setDefaultUseCaches(false);

I suspect the reason is that my original url redirects to another url. The above code should work for all cases.

Crossgrained answered 19/1, 2015 at 22:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.