Refreshing in RestSharp for Windows Phone

故事扮演 提交于 2020-01-04 04:36:08

问题


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)


回答1:


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




回答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();


来源:https://stackoverflow.com/questions/6056409/refreshing-in-restsharp-for-windows-phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!