Udostępnij za pośrednictwem


HttpCacheDirectiveHeaderValueCollection Class

Definition

Represents the value of the Cache-Control HTTP header on HTTP content associated with an HTTP request or response.

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
Inheritance
Object Platform::Object IInspectable HttpCacheDirectiveHeaderValueCollection
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Examples

The following sample code shows a method to get and set the Cache-Control HTTP header on an HttpRequestMessage object using the properties and methods on the HttpCacheDirectiveHeaderValueCollection class.

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

The following sample code shows a method to get and set the Cache-Control HTTP header on an HttpResponseMessage object using the properties and methods on the HttpCacheDirectiveHeaderValueCollection class.

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

Remarks

The HttpCacheDirectiveHeaderValueCollection class represents the value of the Cache-Control HTTP header on HTTP content associated with an HTTP request or an HTTP response.

The CacheControl property on the HttpRequestHeaderCollection returns an HttpCacheDirectiveHeaderValueCollection. The CacheControl property on the HttpResponseHeaderCollection returns an HttpCacheDirectiveHeaderValueCollection.

Collection member lists

For JavaScript, HttpCacheDirectiveHeaderValueCollection has the members shown in the member lists. In addition, HttpCacheDirectiveHeaderValueCollection supports members of Array.prototype and using an index to access items.

Enumerating the collection in C# or Microsoft Visual Basic

You can iterate through an HttpCacheDirectiveHeaderValueCollection object in C# or Microsoft Visual Basic. In many cases, such as using foreach syntax, the compiler does this casting for you and you won't need to cast to IEnumerable<HttpNameValueHeaderValue> explicitly. If you do need to cast explicitly, for example if you want to call GetEnumerator, cast the collection object to IEnumerable<T> with an HttpNameValueHeaderValue constraint.

Properties

MaxAge

Gets or sets the value of the max-age directive in the Cache-Control HTTP header.

MaxStale

Gets or sets the value of the max-stale directive in the Cache-Control HTTP header.

MinFresh

Gets or sets the value of the min-fresh directive in the Cache-Control HTTP header.

SharedMaxAge

Gets or sets the value of the s-maxage directive in the Cache-Control HTTP header.

Size

Gets the number of HttpNameValueHeaderValue objects in the collection.

Methods

Append(HttpNameValueHeaderValue)

Adds a new HttpNameValueHeaderValue item to the end of the collection.

Clear()

Removes all objects from the collection.

First()

Retrieves an iterator to the first HttpNameValueHeaderValue item in the collection.

GetAt(UInt32)

Returns the HttpNameValueHeaderValue at the specified index in the collection.

GetMany(UInt32, HttpNameValueHeaderValue[])

Retrieves the HttpNameValueHeaderValue items that start at the specified index in the collection.

GetView()

Returns an immutable view of the HttpCacheDirectiveHeaderValueCollection.

IndexOf(HttpNameValueHeaderValue, UInt32)

Retrieves the index of an HttpNameValueHeaderValue in the collection.

InsertAt(UInt32, HttpNameValueHeaderValue)

Inserts an HttpNameValueHeaderValue into the collection at the specified index.

ParseAdd(String)

Parses and adds an entry to the HttpCacheDirectiveHeaderValueCollection.

RemoveAt(UInt32)

Removes the entry at the specified index from the HttpCacheDirectiveHeaderValueCollection.

RemoveAtEnd()

Removes the last HttpNameValueHeaderValue item from the collection.

ReplaceAll(HttpNameValueHeaderValue[])

Replaces all the HttpNameValueHeaderValue items in the collection with the specified HttpNameValueHeaderValue items.

SetAt(UInt32, HttpNameValueHeaderValue)

Sets the HttpNameValueHeaderValue at the specified index in the collection.

ToString()

Returns a string that represents the current HttpCacheDirectiveHeaderValueCollection object.

TryParseAdd(String)

Tries to parse and add the specified item to the HttpCacheDirectiveHeaderValueCollection.

Applies to

See also