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, set
Public Shared Property DefaultCachePolicy As RequestCachePolicy
屬性值
HttpRequestCachePolicy,在沒有其他適用的原則時,為這個要求指定作用中的快取原則。
範例
下列程式代碼範例示範如何設定 Web 要求的預設快取原則。
static WebResponse^ GetResponseFromServer2( Uri^ uri )
{
RequestCachePolicy^ policy = gcnew RequestCachePolicy( RequestCacheLevel::NoCacheNoStore );
WebRequest^ request = WebRequest::Create( uri );
WebRequest::DefaultCachePolicy = policy;
WebResponse^ response = request->GetResponse();
Console::WriteLine( L"Policy is {0}.", policy );
Console::WriteLine( L"Is the response from the cache? {0}", response->IsFromCache );
return response;
}
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;
}
備註
如果存在下列條件,此原則會用於此要求:
此要求沒有 DefaultCachePolicy 指定任何屬性。
計算機和應用程式組態檔未指定適用於用來建立此要求的統一資源標識碼 (URI) 快取原則。
快取原則會決定要求的資源是否可以從快取取得,而不是將要求傳送至資源主計算機。
只有在擷取並讀取至數據流的響應數據流時,才會將資源的複本新增至快取。 因此,相同資源的另一個要求可以使用快取複本,視此要求的快取原則層級而定。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應