3

I implemented RestSharp succesfully in my WP7 application, but one issue remains:

When I load resources from the server (for example a GET request on http://localhost:8080/cars), the first time the collection of (in this case) cars is succesfully returned.

When I issue the same request for the second time, I always get the same result as the first time - even when the resources have changed in the meantime. When looking at my server, the second time there is no request issued at all.

I presume there's a caching mechanism implemented in RestSharp, but I see no way to invalidate the cache results.

Are there any ways to manually invalidate the RestSharp for Windows Phone cache results? (Or ways to force the library to get the results from the server)

vstrien
  • 2,547
  • 3
  • 27
  • 47

2 Answers2

3

You can control caching of resources by setting headers on the response your server sends back. If you do not want the resource to be cached then set the cache-control header to no-cache.
It is the server's job to specify how long a resource is good for, the client should do its best to respect that information.

If you really, really want to delete entries in the cache you need to go via the WinINet API

Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
  • Thanks, that does the trick :). Funny, I was worried because the same implementation in RestSharp for Silverlight 4 didn't do this caching. – vstrien May 19 '11 at 13:23
  • I suspect it's a difference in the underlying HttpWebRequest which RestSharp is using. – Matt Lacey May 19 '11 at 13:26
  • 2
    @Matt I don't think it is even in HttpWebRequest. On Windows it is WinINetCache that does the caching. Not sure what the equivalent is in WP7. – Darrel Miller May 19 '11 at 13:53
2

As a quick hack to avoid caching you can append a unique value to the end of the query string. The current DateTime (including seconds and milliseconds if necessary) or a GUID are suitable.

eg.

var uri = "http://example.com/myrequest?rand=" + DateTime.Now().ToString();
Matt Lacey
  • 65,560
  • 11
  • 91
  • 143
  • Would be a good hack if I wasn't able to change things on server-side. Drawback is however that I'll never know where my arguments go (or what kind of effect they'll have) – vstrien May 19 '11 at 13:24