HttpCacheDirectiveHeaderValueCollection クラス

定義

HTTP 要求または応答に関連付けられている HTTP コンテンツの Cache-Control 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
継承
Object Platform::Object IInspectable HttpCacheDirectiveHeaderValueCollection
属性
実装

Windows の要件

デバイス ファミリ
Windows 10 (10.0.10240.0 で導入)
API contract
Windows.Foundation.UniversalApiContract (v1.0 で導入)

次のサンプル コードは、HttpCacheDirectiveHeaderValueCollection クラスのプロパティとメソッドを使用して、HttpRequestMessage オブジェクトの Cache-Control HTTP ヘッダーを取得および設定するメソッドを示しています。

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

次のサンプル コードは、HttpCacheDirectiveHeaderValueCollection クラスのプロパティとメソッドを使用して、HttpResponseMessage オブジェクトの Cache-Control HTTP ヘッダーを取得および設定するメソッドを示しています。

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

注釈

HttpCacheDirectiveHeaderValueCollection クラスは、HTTP 要求または HTTP 応答に関連付けられている HTTP コンテンツの Cache-Control HTTP ヘッダーの値を表します。

HttpRequestHeaderCollectionCacheControl プロパティは、HttpCacheDirectiveHeaderValueCollection を返します。 HttpResponseHeaderCollectionCacheControl プロパティは、HttpCacheDirectiveHeaderValueCollection を返します。

コレクション メンバー リスト

JavaScript の場合、HttpCacheDirectiveHeaderValueCollection にはメンバーリストにメンバーが表示されます。 さらに、HttpCacheDirectiveHeaderValueCollection では 、Array.prototype のメンバーと、インデックスを使用して項目にアクセスできます。

C# または Microsoft Visual Basic でのコレクションの列挙

C# または Microsoft Visual Basic では、HttpCacheDirectiveHeaderValueCollection オブジェクトを反復処理できます。 foreach 構文の使用など、多くの場合、コンパイラによってこのキャストが行われ、明示的に キャストするIEnumerable<HttpNameValueHeaderValue>必要はありません。 GetEnumerator を呼び出す場合など、明示的にキャストする必要がある場合は、HttpNameValueHeaderValue 制約を使用してコレクション オブジェクトを IEnumerable<T> にキャストします。

プロパティ

MaxAge

Cache-Control HTTP ヘッダーの max-age ディレクティブの値を取得または設定します。

MaxStale

Cache-Control HTTP ヘッダーの max-stale ディレクティブの値を取得または設定します。

MinFresh

Cache-Control HTTP ヘッダーの min-fresh ディレクティブの値を取得または設定します。

SharedMaxAge

Cache-Control HTTP ヘッダーの s-maxage ディレクティブの値を取得または設定します。

Size

コレクション内の HttpNameValueHeaderValue オブジェクトの数を取得します。

メソッド

Append(HttpNameValueHeaderValue)

新しい HttpNameValueHeaderValue 項目をコレクションの末尾に追加します。

Clear()

コレクションからすべてのオブジェクトを削除します。

First()

コレクション内の最初の HttpNameValueHeaderValue 項目を指す反復子を取得します。

GetAt(UInt32)

コレクション内の指定したインデックス位置にある HttpNameValueHeaderValue を返します。

GetMany(UInt32, HttpNameValueHeaderValue[])

コレクション内の指定したインデックスから始まる HttpNameValueHeaderValue 項目を取得します。

GetView()

HttpCacheDirectiveHeaderValueCollection の変更できないビューを返します。

IndexOf(HttpNameValueHeaderValue, UInt32)

コレクション内の HttpNameValueHeaderValue のインデックスを取得します。

InsertAt(UInt32, HttpNameValueHeaderValue)

指定したインデックス位置にあるコレクションに HttpNameValueHeaderValue を挿入します。

ParseAdd(String)

HttpCacheDirectiveHeaderValueCollection にエントリを解析して追加します。

RemoveAt(UInt32)

指定したインデックス位置にあるエントリを HttpCacheDirectiveHeaderValueCollection から削除します。

RemoveAtEnd()

コレクションから最後の HttpNameValueHeaderValue 項目を削除します。

ReplaceAll(HttpNameValueHeaderValue[])

コレクション内のすべての HttpNameValueHeaderValue 項目を、指定した HttpNameValueHeaderValue 項目に置き換えます。

SetAt(UInt32, HttpNameValueHeaderValue)

コレクション内の指定したインデックス位置に HttpNameValueHeaderValue を設定します。

ToString()

現在の HttpCacheDirectiveHeaderValueCollection オブジェクトを表す文字列を返します。

TryParseAdd(String)

指定した項目を解析して HttpCacheDirectiveHeaderValueCollection に追加しようとします。

適用対象

こちらもご覧ください