【问题标题】:Windows Phone 7 WebRequest caching?Windows Phone 7 WebRequest 缓存?
【发布时间】:2011-06-13 18:48:08
【问题描述】:

Windows Phone HTTP 客户端会自动缓存吗?

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

【问题讨论】:

    标签: windows-phone-7


    【解决方案1】:

    是的,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();
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2011-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多