WebRequest.CachePolicy Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Bu istek için önbellek ilkesini alır veya ayarlar.
public:
virtual property System::Net::Cache::RequestCachePolicy ^ CachePolicy { System::Net::Cache::RequestCachePolicy ^ get(); void set(System::Net::Cache::RequestCachePolicy ^ value); };
public virtual System.Net.Cache.RequestCachePolicy? CachePolicy { get; set; }
public virtual System.Net.Cache.RequestCachePolicy CachePolicy { get; set; }
member this.CachePolicy : System.Net.Cache.RequestCachePolicy with get, set
Public Overridable Property CachePolicy As RequestCachePolicy
Özellik Değeri
Önbellek RequestCachePolicy ilkesini tanımlayan bir nesne.
Örnekler
Aşağıdaki kod örneği, bir Web isteği için önbellek ilkesini ayarlamayı gösterir.
// The following method demonstrates overriding the
// caching policy for a request.
static WebResponse^ GetResponseNoCache( Uri^ uri )
{
// Set a default policy level for the "http:" and "https" schemes.
HttpRequestCachePolicy^ policy = gcnew HttpRequestCachePolicy( HttpRequestCacheLevel::Default );
HttpWebRequest::DefaultCachePolicy = policy;
// Create the request.
WebRequest^ request = WebRequest::Create( uri );
// Define a cache policy for this request only.
HttpRequestCachePolicy^ noCachePolicy = gcnew HttpRequestCachePolicy( HttpRequestCacheLevel::NoCacheNoStore );
request->CachePolicy = noCachePolicy;
WebResponse^ response = request->GetResponse();
Console::WriteLine( L"IsFromCache? {0}", response->IsFromCache );
return response;
}
// The following method demonstrates overriding the
// caching policy for a request.
public static WebResponse GetResponseNoCache(Uri uri)
{
// Set a default policy level for the "http:" and "https" schemes.
HttpRequestCachePolicy policy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);
HttpWebRequest.DefaultCachePolicy = policy;
// Create the request.
WebRequest request = WebRequest.Create(uri);
// Define a cache policy for this request only.
HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
request.CachePolicy = noCachePolicy;
WebResponse response = request.GetResponse();
Console.WriteLine("IsFromCache? {0}", response.IsFromCache);
return response;
}
Açıklamalar
Geçerli önbellek ilkesi ve istenen kaynağın önbellekte bulunması, önbellekten bir yanıt alınıp alınamayacağını belirler. Önbelleğe alınmış yanıtların kullanılması genellikle uygulama performansını artırır, ancak önbellekteki yanıtın sunucudaki yanıtla eşleşmemesi riski vardır.
Varsayılan önbellek ilkesi, Machine.config yapılandırma dosyasında veya Köprü Metni Aktarım Protokolü (HTTP) veya Güvenli Köprü Metni Aktarım Protokolü (HTTPS) URI şemasını kullanan istekler için özelliği ayarlanarak DefaultCachePolicy belirtilebilir.
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ı kaynak için 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.
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin