Wednesday, September 26, 2012

WebClient and caching in Silverlight + WP7

WebClient and caching in Silverlight + WP7

I am using WebClient to download a JSON file everytime my WP7 application loads. I am loading all the details in one shot and that too from a server endpoint serving this 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.

However, the JSON changes very rarely. So I still need to utilize the caching technique that the WebClient automatically uses. To do this I initially request a call to the server's JSON version something like, http://myserver/JSONVersion. This JSONVersion gets updated any time JSON is updated.

Once I get it, i append it to my url 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. If so, please let me know.

Answers & Comments...




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog