I’m writing an application for Windows Phone 7 Mango that should be hitting the marketplace shortly. The application allows you to access the real-time feeds that report MBTA bus locations and predictions for when buses will arrive at a particular stop. These feeds are exposed as REST services.
Yesterday, I found that I wasn’t able to refresh bus stop predictions and, after I drilled into the problem, I discovered that Mango was caching the result of the request. Same request URL always returned the same response data. Well, this wasn’t helpful because the data changes from minute to minute.
Problem: Windows Phone 7.5 (Mango) returns the same HTTP response result for a given request URL sent to a REST web service.
Cause: The HttpWebRequest and HttpWebResponse objects that are returned by WebRequest.Create(string url) use caching that is based on the URL text. If the text of the URL doesn’t change (same base URL plus query string parameters), the caching system assumes it can save time and return the same data.
Solution / Workaround: Append the current DateTime.Now.Ticks value to the WebRequest query string. This makes the web requests reasonably unique from request to request and the responses become un-cacheable.
I hope this helps.
Leave a Reply