WebRequest.DefaultCachePolicy Özellik

Tanım

Bu istek için varsayılan önbellek ilkesini alır veya ayarlar.

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; }
member this.DefaultCachePolicy : System.Net.Cache.RequestCachePolicy with get, set
Public Shared Property DefaultCachePolicy As RequestCachePolicy

Özellik Değeri

RequestCachePolicy

HttpRequestCachePolicy Başka bir ilke geçerli olmadığında bu istek için geçerli olan önbellek ilkesini belirten bir.

Örnekler

Aşağıdaki kod örneği, Web istekleri için varsayılan önbellek ilkesini ayarlamayı gösterir.

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

Açıklamalar

Bu ilke, aşağıdaki koşullar varsa bu istek için kullanılır:

  • Bu istek için belirtilen özellik yok DefaultCachePolicy .

  • Makine ve uygulama yapılandırma dosyaları, bu isteği oluşturmak için kullanılan Tekdüzen Kaynak Tanımlayıcısı (URI) için geçerli bir önbellek ilkesi belirtmez.

Önbellek ilkesi, isteği kaynak ana bilgisayarına göndermek yerine istenen kaynağın önbellekten alınıp alınamayacağını belirler.

Bir kaynağın kopyası önbelleğe yalnızca kaynağın yanıt akışı alınır ve akışın sonuna okunursa eklenir. Bu nedenle aynı kaynağa yönelik başka bir istek, bu isteğin önbellek ilkesi düzeyine bağlı olarak önbelleğe alınmış bir kopya kullanabilir.

Şunlara uygulanır

Ayrıca bkz.