How to disable caching using WebClient and Windows Phone 7

I call the REST web service and the mobile application retrieves the results from its cache and is not going to the server.

I saw other suggested fixes (a similar problem and a similar problem2 ) but the Cache property is not available in silverlight 4.

Does anyone have an idea how to get Silverlight 4 on Windows Phone 7 to make a request and not get into the cache?

+8
windows-phone-7 cache-control webclient
source share
4 answers

Although not ideal, a simple solution is to send something like a garbage field with a DateTime.Now value. Thus, the value is always completely new and will never be cached. If you did this in standard querysting, for example:

 "&junk=" + DateTime.Now; 
+16
source share

I also hit this issue on overflow 7 while talking to StackApps - the only thing I could think of was adding a random add variable at the end of the HTTP / REST request.

+5
source share

The most proposed solution is the same as that of William Melanie. But this is not ideal, and some services reject requests with unknown parameters or any parameter. In this case, it is cleaner and more reliable to use the IfModifiedSince header as follows:

  WebClient wc = new WebClient(); wc.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.UtcNow.ToString(); wc.DownloadStringCompleted += wc_DownloadStringCompleted; wc.DownloadStringAsync(new Uri(bitstampUrl)); 
+3
source share
 WebClient wc = new WebClient(); wc.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.UtcNow.ToString(); 

worked for me

0
source share

All Articles