From 296d3ca2100007992cef4bf7e581f863b9b26a47 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 21 Jun 2011 21:32:10 +0000 Subject: [PATCH] Disable URLConnection caches when downloading control files. --- .../java/com/threerings/getdown/data/Application.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/threerings/getdown/data/Application.java b/src/main/java/com/threerings/getdown/data/Application.java index 84b28c9..2b75d6f 100644 --- a/src/main/java/com/threerings/getdown/data/Application.java +++ b/src/main/java/com/threerings/getdown/data/Application.java @@ -42,6 +42,7 @@ import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.net.URLConnection; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.nio.channels.OverlappingFileLockException; @@ -1363,7 +1364,14 @@ public class Application InputStream fin = null; FileOutputStream fout = null; try { - fin = targetURL.openStream(); + URLConnection uconn = targetURL.openConnection(); + // we have to tell Java not to use caches here, otherwise it will cache any request for + // same URL for the lifetime of this JVM (based on the URL string, not the URL object); + // if the getdown.txt file, for example, changes in the meanwhile, we would never hear + // about it; turning off caches is not a performance concern, because when Getdown asks + // to download a file, it expects it to come over the wire, not from a cache + uconn.setUseCaches(false); + fin = uconn.getInputStream(); fout = new FileOutputStream(target); StreamUtil.copy(fin, fout); } finally {