A few weeks ago I mentioned that I was experiencing unwanted http caching 
(I mentioned it here because I wasn't sure if the cause of the problem was 
the Android OS performing the caching in a way that didn't make sense to 
me).  At the time, it was suggested that I experiment with getUseCaches() 
and setUseCaches().  This has definitely not solved the problem.  First of 
all, it does indeed appear that caching is enabled by default (as is 
GZipping the stream interestingly, I think I've read about this 
somewhere).  However, setting caching false doesn't help.  Not only does my 
app not confidently load an updated version of the file from the server, 
but it doesn't even detect that the file is gone from the server (if I 
change its name for example).  Rather, the app still happily retrieves the 
cached version of the file, even though I'm calling setUseCaches(false).  
Does anyone have any thoughts on how else to fix this problem?  I know 
there is a solution because the phone's web browser app (actually, I'm 
using Dolphin) properly loads the server version of the file every time.

Once again, I don't mean to bring this up on an Android forum if it really 
isn't an Android issue...but I'm not sure whether the problem is coming 
from the Android system for some reason (I'm not sure whether I should 
expect my code to work in any other Java environment, just not Android).  
Where else might the cache be coming from if the URLConnection's useCaches 
variable is definitely false (verified as I step over setUseCaches(false) 
in the debugger)?

I'm sorry if this is off-topic, I appreciate any help.  Here's how I load 
the file:

    String address = "httpUrlOfFileOnMyWebserver";
    URL url = new URL(address);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    if (conn.getUseCaches())
        conn.setUseCaches(false);
    InputStream is = (InputStream)conn.getContent();
    Reader reader = new InputStreamReader(is, "UTF-8");
    StringWriter writer = new StringWriter();
    char[] buffer = new char[1024];
    for (int length = 0; (length = reader.read(buffer)) > 0;)
        writer.write(buffer, 0, length);
    is.close();
    reader.close();
    writer.close();
    String fileStr = writer.toString();

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to