HttpCacheDirectiveHeaderValueCollection Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mewakili nilai header HTTP Cache-Control pada konten HTTP yang terkait dengan permintaan atau respons HTTP.
public ref class HttpCacheDirectiveHeaderValueCollection sealed : IIterable<HttpNameValueHeaderValue ^>, IVector<HttpNameValueHeaderValue ^>, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class HttpCacheDirectiveHeaderValueCollection final : IIterable<HttpNameValueHeaderValue>, IVector<HttpNameValueHeaderValue>, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class HttpCacheDirectiveHeaderValueCollection final : IIterable<HttpNameValueHeaderValue>, IVector<HttpNameValueHeaderValue>, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class HttpCacheDirectiveHeaderValueCollection : IEnumerable<HttpNameValueHeaderValue>, IList<HttpNameValueHeaderValue>, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class HttpCacheDirectiveHeaderValueCollection : IEnumerable<HttpNameValueHeaderValue>, IList<HttpNameValueHeaderValue>, IStringable
Public NotInheritable Class HttpCacheDirectiveHeaderValueCollection
Implements IEnumerable(Of HttpNameValueHeaderValue), IList(Of HttpNameValueHeaderValue), IStringable
- Warisan
- Atribut
- Penerapan
Persyaratan Windows
Rangkaian perangkat |
Windows 10 (diperkenalkan dalam 10.0.10240.0)
|
API contract |
Windows.Foundation.UniversalApiContract (diperkenalkan dalam v1.0)
|
Contoh
Kode sampel berikut menunjukkan metode untuk mendapatkan dan mengatur header HTTP Cache-Control pada objek HttpRequestMessage menggunakan properti dan metode pada kelas HttpCacheDirectiveHeaderValueCollection.
using System;
using Windows.Web.Http;
using Windows.Web.Http.Headers;
public void DemonstrateHeaderRequestCacheControl() {
var request = new HttpRequestMessage();
bool parsedOk = false;
// Set the header with a string.
parsedOk = request.Headers.CacheControl.TryParseAdd("no-store");
// Set the header with a strong type.
request.Headers.CacheControl.Add(new HttpNameValueHeaderValue("max-age", "10"));
// Get the strong type out
foreach (var value in request.Headers.CacheControl) {
System.Diagnostics.Debug.WriteLine("One of the CacheControl values: {0}={1}", value.Name, value.Value);
}
// The ToString() is useful for diagnostics, too.
System.Diagnostics.Debug.WriteLine("The CacheControl ToString() results: {0}", request.Headers.CacheControl.ToString());
}
Kode sampel berikut menunjukkan metode untuk mendapatkan dan mengatur header HTTP Cache-Control pada objek HttpResponseMessage menggunakan properti dan metode pada kelas HttpCacheDirectiveHeaderValueCollection.
using System;
using Windows.Web.Http;
using Windows.Web.Http.Headers;
public void DemonstrateHeaderResponseCacheControl() {
var response = new HttpResponseMessage();
// Set the header with a string
response.Headers.CacheControl.TryParseAdd("public");
// Set the header with a strong type
response.Headers.CacheControl.Add(new HttpNameValueHeaderValue("max-age", "30"));
// Get the strong type out
foreach (var value in response.Headers.CacheControl) {
System.Diagnostics.Debug.WriteLine("CacheControl {0}={1}", value.Name, value.Value);
}
// The ToString() is useful for diagnostics, too.
System.Diagnostics.Debug.WriteLine("The CacheControl ToString() results: {0}", response.Headers.CacheControl.ToString());
}
Keterangan
Kelas HttpCacheDirectiveHeaderValueCollection mewakili nilai header HTTP Cache-Control pada konten HTTP yang terkait dengan permintaan HTTP atau respons HTTP.
Properti CacheControl pada HttpRequestHeaderCollection mengembalikan HttpCacheDirectiveHeaderValueCollection. Properti CacheControl pada HttpResponseHeaderCollection mengembalikan HttpCacheDirectiveHeaderValueCollection.
Daftar anggota koleksi
Untuk JavaScript, HttpCacheDirectiveHeaderValueCollection memiliki anggota yang diperlihatkan dalam daftar anggota. Selain itu, HttpCacheDirectiveHeaderValueCollection mendukung anggota Array.prototype dan menggunakan indeks untuk mengakses item.
Menghitung koleksi dalam C# atau Microsoft Visual Basic
Anda dapat melakukan iterasi melalui objek HttpCacheDirectiveHeaderValueCollection di C# atau Microsoft Visual Basic. Dalam banyak kasus, seperti menggunakan sintaks foreach , pengkompilasi melakukan transmisi ini untuk Anda dan Anda tidak perlu mentransmisikan untuk IEnumerable<HttpNameValueHeaderValue>
secara eksplisit. Jika Anda perlu mentransmisikan secara eksplisit, misalnya jika Anda ingin memanggil GetEnumerator, transmisikan objek koleksi ke IEnumerable<T> dengan batasan HttpNameValueHeaderValue .
Properti
MaxAge |
Mendapatkan atau menetapkan nilai direktif usia maksimum di header HTTP Cache-Control . |
MaxStale |
Mendapatkan atau mengatur nilai direktif max-stale di header HTTP Cache-Control . |
MinFresh |
Mendapatkan atau menetapkan nilai direktif min-fresh di header HTTP Cache-Control . |
SharedMaxAge |
Mendapatkan atau mengatur nilai direktif s-maxage di header HTTP Cache-Control . |
Size |
Mendapatkan jumlah objek HttpNameValueHeaderValue dalam koleksi. |
Metode
Berlaku untuk
Lihat juga
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk