Is Windows Phone HTTP client caching automatically ?
When using Fiddler, I don't see all my requests.
Is Windows Phone HTTP client caching automatically ?
When using Fiddler, I don't see all my requests.
Yes, HttpWeRequest (whihc is used internally by WebClient-if you're using that) has built in caching which can be quite aggressive, depending on your requirements.
The common work around for this is to append and extra value to the querystring which has no meaning other than to work around the caching of previous calls.
Something like:
var mrUri = "http://something.com/path/file.ext?nocache=" + Guid.NewGuid();
or
var mrUri = "http://something.com/path/file.ext?nocache=" + DateTime.UtcNow.ToString();
I had that problem recently. Some blog posts about it :
http://ayende.com/blog/4755/silverlight-and-http-and-caching-oh-my
http://www.nickharris.net/2010/10/windows-phone-7-httpwebrequest-returns-same-response-from-cache/
Here is the code I'm using with Spring.NET REST Client Framework to force no caching by default:
public class NoCacheRequestInterceptor : IClientHttpRequestFactoryInterceptor
{
public IClientHttpRequest Create(IClientHttpRequestFactoryCreation creation)
{
creation.Uri = new Uri(String.Format("{0}{1}nocache={2}",
creation.Uri.ToString(),
String.IsNullOrEmpty(creation.Uri.Query) ? "?" : "&",
DateTime.Now.Ticks.ToString()));
return creation.Create();
}
}
RestTemplate client = new RestTemplate("http://www.example.com/");
client.RequestInterceptors.Add(new NoCacheRequestInterceptor());
// ..
string result = client.GetForObject<string>("category/{id}", 4);