Does Android cache http-requested data?

I keep a small text file with various app-settings on my webserver.  When 
my app launches, it sends an http request to my webserver to grab the text 
file and retrieve the settings.  This enables me to update the settings of 
an app installed on a phone "in the field" from the server.

The problem is, when I update the text file on the server, I usually don't 
see an immediate change in the text file retrieved by my app.  It can take 
hours for the change to show up in my app's http requests.  I know that the 
problem is not merely one of the file updating through various 
buffers/caches on the webserver because I can see the new version of the 
file if I load the same URL in a web browser...including a web browser on 
the exact same Android device I am running my app on...so a web browser 
(even one on the phone itself) sees the updated file immediately after I 
change it, but my app doesn't see it for several hours.

It feels like Android is caching previous http request results and 
returning those to apps that make repeated requests instead of reloading 
the URLs from the web...and it takes a very long time to label this 
presumed cache as stale and reload the file from the server...several hours.

On a side note, I have tried killing the app to make sure it's totally 
gone.  I have even tried rebooting the phone and yet the problem still 
persists...which is mind-boggling.

I am quite flummoxed.  I am aware that Android is requesting and receiving 
a GZipInputStream, and I can see the input stream's type in the debugger, 
but that seems irrelevant to my issue.

Here's how I pull the text file from the web server into my app.  Any ideas 
why a browser on the same device successfully retrieves the updated file 
and my code doesn't?

String address = "http://URL_of_text_file_on_my_webserver.txt";;
URL url = new URL(address);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
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();

Thanks.

-- 
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