4
votes

I have an issue which is driving me crazy. I searched for hours for an answer without any luck. I am developing a WINRT/Windows Phone 8.1 App where I call a RESTful webservice from the following code:

HttpClient httpClient = new HttpClient();
HttpResponseMessage response = await httpClient.GetAsync(new Uri("my_secret_uri"));
string data = await response.Content.ReadAsStringAsync();
MessageDialog dialog = new MessageDialog(data);
await dialog.ShowAsync();

This works fine and it returns the correct data. I then do the following:

  1. Navigate away from the page displaying the data
  2. Manually change some of the data in the Webservice database
  3. Navigate back to the page

I would now expect it to pull the new data which I changed in step #2 but it still returns the initial data. If I enter 'my_secret_uri' in a webbrowser it correctly displays the modified data. If I stop the App and launch it again it also correctly shows the modified data.

It is as if the data that was initially pulled is cached as long as the App is running.

Any idea what is wrong?

1
When is that code called? What method is it in?Jeroen Vannevel

1 Answers

2
votes

Windows Phone has a quite aggressive web cache. Unless your server explicitly sets a cache duration header, it will return all requests with the same Uri directly from the cache without even contacting your server.

You can turn off this behavior by:

  1. Setting a cache duration header (cache-control: no-cache, etc.).
  2. Adding a random number to your requests query string.