Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Does Android cache http-requested data?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Keith Wiley  
View profile  
 More options Oct 14 2012, 3:58 am
From: Keith Wiley <kbwi...@gmail.com>
Date: Sun, 14 Oct 2012 00:58:55 -0700 (PDT)
Local: Sun, Oct 14 2012 3:58 am
Subject: Does Android cache http-requested data?

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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
TreKing  
View profile  
 More options Oct 14 2012, 4:15 am
From: TreKing <treking...@gmail.com>
Date: Sun, 14 Oct 2012 08:10:24 +0000
Local: Sun, Oct 14 2012 4:10 am
Subject: Re: [android-developers] Does Android cache http-requested data?

On Sun, Oct 14, 2012 at 7:58 AM, Keith Wiley <kbwi...@gmail.com> wrote:
> Any ideas why a browser on the same device successfully retrieves the
> updated file and my code doesn't?

Not sure, but looking at the API, there's this:
http://developer.android.com/reference/java/net/URLConnection.html#ge...

And an equivalent set function. Have you tried that?

--------------------------------------------------------------------------- ----------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
transit tracking app for Android-powered devices


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Keith Wiley  
View profile  
 More options Oct 14 2012, 4:36 am
From: Keith Wiley <kbwi...@gmail.com>
Date: Sun, 14 Oct 2012 01:36:41 -0700 (PDT)
Local: Sun, Oct 14 2012 4:36 am
Subject: Re: [android-developers] Does Android cache http-requested data?

Thanks, I'll definitely look into that.  I can see that it the cache value
is set to true but I can't test whether turning it off fixes the problem
right now.  I'll try it later.

That seems like a very strong possibility for this issue.  Thanks again.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thanh Tung Nguyen  
View profile  
 More options Oct 14 2012, 4:49 am
From: Thanh Tung Nguyen <tung6...@gmail.com>
Date: Sun, 14 Oct 2012 01:49:38 -0700 (PDT)
Local: Sun, Oct 14 2012 4:49 am
Subject: Re: Does Android cache http-requested data?

thanks a lot

Vào 14:58:55 UTC+7 Chủ nhật, ngày 14 tháng mười năm 2012, Keith Wiley đă
viết:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jan Burse  
View profile  
 More options Oct 14 2012, 5:16 am
From: Jan Burse <janbu...@fastmail.fm>
Date: Sun, 14 Oct 2012 11:12:55 +0200
Local: Sun, Oct 14 2012 5:12 am
Subject: Re: Does Android cache http-requested data?
Keith Wiley schrieb:

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

Caching of web server chains can be very elaborate. See
for example here:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
14.9 Cache-Control

So eventually setUseCache() to false can help, but might
slowdown your requests.

It could be also an issue on the server side, that for example
the server emits a wrong "Expires" header, this header is also
described in the above RFC.

If you re-access the same file multiple times and if you
can remember the modified date, then the setIfModifiedDate()
comes very handy. If the data on the server doesn't have a
newer modified date, you will get:

     HTTP_NOT_MODIFIED = 304;

Bye


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kristopher Micinski  
View profile  
 More options Oct 14 2012, 10:15 am
From: Kristopher Micinski <krismicin...@gmail.com>
Date: Sun, 14 Oct 2012 10:13:56 -0400
Local: Sun, Oct 14 2012 10:13 am
Subject: Re: [android-developers] Does Android cache http-requested data?
FYI depending on how caching happens turning off the device won't
necessarily solve your problems.

kris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Keith Wiley  
View profile  
 More options Oct 14 2012, 11:30 am
From: Keith Wiley <kbwi...@gmail.com>
Date: Sun, 14 Oct 2012 08:30:11 -0700 (PDT)
Local: Sun, Oct 14 2012 11:30 am
Subject: Re: Does Android cache http-requested data?

Thanks for the great feedback on this everyone!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
lbendlin  
View profile  
 More options Oct 15 2012, 10:31 am
From: lbendlin <l...@bendlin.us>
Date: Mon, 15 Oct 2012 07:31:18 -0700 (PDT)
Local: Mon, Oct 15 2012 10:31 am
Subject: Re: Does Android cache http-requested data?

To fight the caching, add a random parameter to your URL request.

http://blabla.com/page.htm?r=0.251333

etc


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bob  
View profile  
 More options Oct 15 2012, 10:50 am
From: bob <b...@coolfone.comze.com>
Date: Mon, 15 Oct 2012 07:50:45 -0700 (PDT)
Local: Mon, Oct 15 2012 10:50 am
Subject: Re: Does Android cache http-requested data?

If you really need to avoid caching, there is always java.net.Socket.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »