WebRequest.DefaultCachePolicy 属性    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置此请求的默认缓存策略。
public:
 static property System::Net::Cache::RequestCachePolicy ^ DefaultCachePolicy { System::Net::Cache::RequestCachePolicy ^ get(); void set(System::Net::Cache::RequestCachePolicy ^ value); };public static System.Net.Cache.RequestCachePolicy? DefaultCachePolicy { get; set; }public static System.Net.Cache.RequestCachePolicy DefaultCachePolicy { get; set; }static member DefaultCachePolicy : System.Net.Cache.RequestCachePolicy with get, setPublic Shared Property DefaultCachePolicy As RequestCachePolicy属性值
一个 HttpRequestCachePolicy,当其他策略不适用时,指定此请求生效的缓存策略。
示例
下面的代码示例演示如何设置 Web 请求的默认缓存策略。
        public static WebResponse GetResponseFromServer2(Uri uri)
{
     RequestCachePolicy policy =
        new  RequestCachePolicy( RequestCacheLevel.NoCacheNoStore);
    WebRequest request = WebRequest.Create(uri);
    WebRequest.DefaultCachePolicy = policy;
    WebResponse response = request.GetResponse();
    Console.WriteLine("Policy is {0}.", policy.ToString());
    Console.WriteLine("Is the response from the cache? {0}", response.IsFromCache);
    return response;
}
注解
谨慎
              WebRequest、HttpWebRequest、ServicePoint和 WebClient 已过时,不应将其用于新开发。 请改用 HttpClient。
如果存在以下条件,此策略将用于此请求:
- 没有为此请求指定的 DefaultCachePolicy 属性。 
- 计算机和应用程序配置文件未指定适用于用于创建此请求的统一资源标识符(URI)的缓存策略。 
缓存策略确定请求的资源是否可以从缓存中获取,而不是将请求发送到资源主机计算机。
仅当检索资源响应流并将其读取到流的末尾时,资源的副本才会添加到缓存中。 因此,针对同一资源的另一个请求可以使用缓存副本,具体取决于此请求的缓存策略级别。