[英]WebClient and caching in Silverlight + WP7
I am using WebClient to download a JSON file everytime my WP7 application loads. 每次加载WP7应用程序时,我都在使用WebClient下载JSON文件。 I am loading all the details in one shot and that too from a server endpoint serving this JSON.
我正在一次加载所有详细信息,并且也从提供此JSON的服务器端点加载了所有详细信息。 The obvious problem I faced was the caching.
我面临的明显问题是缓存。 It was always loading the stale copy.
它总是在加载陈旧的副本。 But I tackled this issue by adding a dummy URL paramater at the end.
但是我通过在最后添加一个虚拟URL参数解决了这个问题。
However, the JSON changes very rarely. 但是,JSON很少更改。 So I still need to utilize the caching technique that the WebClient automatically uses.
因此,我仍然需要利用WebClient自动使用的缓存技术。 To do this I initially request a call to the server's JSON version something like,
http://myserver/JSONVersion
. 为此,我最初请求调用服务器的JSON版本,例如
http://myserver/JSONVersion
。 This JSONVersion gets updated any time JSON is updated. 每当更新JSON时,此JSONVersion都会更新。
Once I get it, i append it to my url http://myserver/myjson.json?v=(JSONVERSION)
. 收到后,将其附加到我的网址
http://myserver/myjson.json?v=(JSONVERSION)
。 This has solved my entire problem. 这解决了我的整个问题。 However, I feel this is very ugly and has unnecessary excess code+logic floating around.
但是,我觉得这很丑陋,并且有多余的多余代码和逻辑浮动。 I am hoping the HTTP Cache headers have a work around similar to the one that I am having.
我希望HTTP Cache标头能与我所拥有的相似。 If so, please let me know.
如果是这样,请告诉我。
显然,我没有找到比现在更好的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.