共用方式為


RequestCachePolicy.Level 屬性

定義

取得 RequestCacheLevel 建構此實例時指定的值。

public:
 property System::Net::Cache::RequestCacheLevel Level { System::Net::Cache::RequestCacheLevel get(); };
public System.Net.Cache.RequestCacheLevel Level { get; }
member this.Level : System.Net.Cache.RequestCacheLevel
Public ReadOnly Property Level As RequestCacheLevel

屬性值

一個 RequestCacheLevel 指定使用 WebRequest 物件取得資源快取行為的值。

範例

以下程式碼範例會建立一個 CacheOnly 政策並發送請求。

public static WebResponse GetResponseFromCache(Uri uri)
{
     RequestCachePolicy policy =
        new  RequestCachePolicy( RequestCacheLevel.CacheOnly);
    WebRequest request = WebRequest.Create(uri);
    request.CachePolicy = policy;
    WebResponse response = request.GetResponse();
    Console.WriteLine("Policy level is {0}.", policy.Level.ToString());
    Console.WriteLine("Is the response from the cache? {0}", response.IsFromCache);
    return response;
}

備註

應用程式通常使用 Default 作為快取政策層級。 透過層 Default 級,有效的快取政策由當前快取政策及快取內容的年齡決定。 若不符合null,屬性WebRequest.CachePolicy決定請求所生效的快取政策。

應用程式域的預設政策可透過 DefaultCachePolicy 應用程式或機器設定檔設定。 更多資訊請參閱<請求快取>元素(網路設定)。

適用於

另請參閱