Windows Phone HTTP客户端是否自动缓存?
使用Fiddler时,我没有看到我的所有要求。
答案 0 :(得分:7)
是的,HttpWeRequest(webClient内部使用的是whihc - 如果你正在使用它)内置了缓存,这可能非常具有侵略性,具体取决于你的要求。
对此的常见解决方法是向查询字符串附加值和额外值,除了解决先前调用的缓存之外没有任何意义。
类似的东西:
var mrUri = "http://something.com/path/file.ext?nocache=" + Guid.NewGuid();
或
var mrUri = "http://something.com/path/file.ext?nocache=" + DateTime.UtcNow.ToString();
答案 1 :(得分:1)
我最近遇到了这个问题。关于它的一些博客文章:
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/
以下是我与Spring.NET REST Client Framework一起使用的代码,默认情况下不强制缓存:
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);