开发者

Refreshing in RestSharp for Windows Phone

开发者 https://www.devze.com 2023-03-07 11:39 出处:网络
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

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 th开发者_运维百科e library to get the results from the server)


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


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消