8

I am making a call to a REST web service and the mobile app is retrieving the results from its cache and not going to the server.

I have seen other suggested fixes (similar issue and similar issue2) but the Cache property is not available in silverlight 4.

Does anyone have an idea of how to force silverlight 4 on windows phone 7 to make a request and not hit the cache?

1
  • Note that WP7 uses a variant of Silverlight 3, not 4.
    – Matt Lacey
    Commented Mar 3, 2011 at 9:20

4 Answers 4

16

Although not ideal, a easy solution is to send something like the field "junk" with the value DateTime.Now. That way, a value is always brand new, and will never get cached. If you were doing this in a standard querysting for example:

"&junk=" + DateTime.Now;
1
  • 9
    This would be more cleaner "?nocache=" + Environment.TickCount
    – bragboy
    Commented Jul 20, 2012 at 11:26
5

I've hit this problem too on overflow 7 talking to StackApps - the only thing I could think of was to add an addition random variable to the end of the HTTP/REST request.

3

The most proposed solution is the same as William Melani's. But it 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));
0
WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.UtcNow.ToString();

worked for me

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.