Windows Phone 7 WebRequest缓存?

问题描述:

Windows Phone HTTP客户端是否自动缓存?Windows Phone 7 WebRequest缓存?

使用Fiddler时,我看不到所有的请求。

是的,HttpWeRequest(由WebClient在内部使用,如果您使用的话)内置缓存,根据您的要求,缓存可能非常具有侵略性。

常见的解决方法是为查询字符串添加额外的值,除了解决先前调用的缓存外没有其他意义。

喜欢的东西:

var mrUri = "http://something.com/path/file.ext?nocache=" + Guid.NewGuid(); 

var mrUri = "http://something.com/path/file.ext?nocache=" + DateTime.UtcNow.ToString(); 
+3

我觉得这个解决方案是更好的HTTP ://stackoverflow.com/a/9208636/269905 – mehmet6parmak 2013-09-12 14:27:24

最近我有这个问题。关于它的一些博客文章:

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);