Class HttpCacheableOptions
- Namespace
- Cuemon.AspNetCore.Mvc.Filters.Cacheable
- Assembly
- Cuemon.AspNetCore.Mvc.dll
Specifies options that is related to the HttpCacheableFilter.
public class HttpCacheableOptions : IValidatableParameterObject, IParameterObject
- Inheritance
-
HttpCacheableOptions
- Implements
Examples
The following example configures with a custom Cache-Control header and manually adds both cacheable filters used by .
using System;
using Cuemon.AspNetCore.Mvc.Filters.Cacheable;
using Microsoft.Net.Http.Headers;
namespace MyApp.Examples;
public static class HttpCacheableOptionsExample
{
public static void Demonstrate()
{
var options = new HttpCacheableOptions
{
CacheControl = new CacheControlHeaderValue
{
MaxAge = TimeSpan.FromMinutes(15),
Public = true,
MustRevalidate = false
}
};
options.Filters.Add(new HttpEntityTagHeaderFilter(o => o.UseEntityTagResponseParser = true));
options.Filters.Add(new HttpLastModifiedHeaderFilter());
Console.WriteLine(options.UseCacheControl);
Console.WriteLine(options.Filters.Count);
Console.WriteLine(options.CacheControl.MaxAge);
}
}
Constructors
HttpCacheableOptions()
Initializes a new instance of the HttpCacheableOptions class.
public HttpCacheableOptions()
Remarks
The following table shows the initial property values for an instance of HttpCacheableOptions.
| Property | Initial Value |
|---|---|
| Filters | new List{ICacheableAsyncResultFilter}() |
| CacheControl | new CacheControlHeaderValue() { MaxAge = TimeSpan.FromMinutes(5), MustRevalidate = true, Private = true }; |
Properties
CacheControl
Gets or sets the Cache-Control header that is applied to objects implementing the ICacheableObjectResult interface.
public CacheControlHeaderValue CacheControl { get; set; }
Property Value
- CacheControlHeaderValue
The Cache-Control header that is applied to objects implementing the ICacheableObjectResult interface.
Filters
Gets the filters that will be invoked one by one in OnResultExecutionAsync(ResultExecutingContext, ResultExecutionDelegate).
public IList<ICacheableAsyncResultFilter> Filters { get; set; }
Property Value
- IList<ICacheableAsyncResultFilter>
The filters that will be invoked by HttpCacheableFilter.
UseCacheControl
Gets a value indicating whether this instance has an CacheControl.
public bool UseCacheControl { get; }
Property Value
- bool
trueif this instance has an CacheControl; otherwise,false.
Methods
ValidateOptions()
Determines whether the public read-write properties of this instance are in a valid state.
public void ValidateOptions()
Remarks
This method is expected to throw exceptions when one or more conditions fails to be in a valid state.
Exceptions
- InvalidOperationException
Filters cannot be null.