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();
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?
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.
> 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?
> 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:
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:
On Sun, Oct 14, 2012 at 3:58 AM, Keith Wiley <kbwi...@gmail.com> wrote:
> 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?
> --
> 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+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
On Sunday, October 14, 2012 2:58:55 AM UTC-5, Keith Wiley wrote:
> 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?