Table of Contents

Class CacheableAsyncResultFilterExtensions

Namespace
Cuemon.Extensions.AspNetCore.Mvc.Filters.Cacheable
Assembly
Cuemon.Extensions.AspNetCore.Mvc.dll

Extension methods for the ICacheableAsyncResultFilter interface.

public static class CacheableAsyncResultFilterExtensions
Inheritance
CacheableAsyncResultFilterExtensions

Examples

The following example configures the same cache-filter collection patterns exercised by the unit tests: use the convenience methods for the default pipeline, or switch to the generic overloads when you need explicit ordering and option control.

using System;
using Cuemon.AspNetCore.Mvc.Filters.Cacheable;
using Cuemon.Extensions.AspNetCore.Mvc.Filters.Cacheable;

namespace Cuemon.Extensions.AspNetCore.Mvc.Filters.Cacheable.DocExamples;

public sealed class CacheableAsyncResultFilterExtensionsExample
{
    public HttpCacheableOptions CreateDefaultProfile()
    {
        var options = new HttpCacheableOptions();
        options.Filters.AddLastModifiedHeader();
        options.Filters.AddEntityTagHeader();
        return options;
    }

    public HttpCacheableOptions CreateCustomProfile()
    {
        var options = new HttpCacheableOptions();
        options.Filters.AddFilter<HttpEntityTagHeaderFilter, HttpEntityTagHeaderOptions>(entityTag =>
        {
            entityTag.UseEntityTagResponseParser = true;
        });
        options.Filters.InsertFilter<HttpLastModifiedHeaderFilter>(0);
        return options;
    }

    public void Describe()
    {
        var defaultProfile = CreateDefaultProfile();
        var customProfile = CreateCustomProfile();

        Console.WriteLine($"{defaultProfile.Filters.Count} default filters, {customProfile.Filters.Count} custom filters.");
    }
}

Methods

AddEntityTagHeader(IList<ICacheableAsyncResultFilter>, Action<HttpEntityTagHeaderOptions>)

Adds an HttpEntityTagHeaderFilter filter to the list.

public static void AddEntityTagHeader(this IList<ICacheableAsyncResultFilter> filters, Action<HttpEntityTagHeaderOptions> setup = null)

Parameters

filters IList<ICacheableAsyncResultFilter>

The list of cache related HTTP filters.

setup Action<HttpEntityTagHeaderOptions>

The HttpEntityTagHeaderOptions which need to be configured.

AddFilter<T>(IList<ICacheableAsyncResultFilter>)

Adds a cache related HTTP filter to the list.

public static void AddFilter<T>(this IList<ICacheableAsyncResultFilter> filters) where T : ICacheableAsyncResultFilter

Parameters

filters IList<ICacheableAsyncResultFilter>

The list of cache related HTTP head filters.

Type Parameters

T

The type of the ICacheableAsyncResultFilter.

AddFilter<T, TOptions>(IList<ICacheableAsyncResultFilter>, Action<TOptions>)

Adds a cache related HTTP filter to the list.

public static void AddFilter<T, TOptions>(this IList<ICacheableAsyncResultFilter> filters, Action<TOptions> setup = null) where T : ICacheableAsyncResultFilter where TOptions : class, IParameterObject, new()

Parameters

filters IList<ICacheableAsyncResultFilter>

The list of cache related HTTP filters.

setup Action<TOptions>

The Action<T> which may be configured.

Type Parameters

T

The type of the ICacheableAsyncResultFilter.

TOptions

The type of delegate setup to configure T.

AddLastModifiedHeader(IList<ICacheableAsyncResultFilter>, Action<HttpLastModifiedHeaderOptions>)

Adds an HttpLastModifiedHeaderFilter filter to the list.

public static void AddLastModifiedHeader(this IList<ICacheableAsyncResultFilter> filters, Action<HttpLastModifiedHeaderOptions> setup = null)

Parameters

filters IList<ICacheableAsyncResultFilter>

The list of cache related HTTP filters.

setup Action<HttpLastModifiedHeaderOptions>

The HttpLastModifiedHeaderOptions which need to be configured.

InsertFilter<T>(IList<ICacheableAsyncResultFilter>, int)

Inserts a cache related HTTP filter to the list at the specified index.

public static void InsertFilter<T>(this IList<ICacheableAsyncResultFilter> filters, int index) where T : ICacheableAsyncResultFilter

Parameters

filters IList<ICacheableAsyncResultFilter>

The list of cache related HTTP filters.

index int

The zero-based index at which a HTTP related filter should be inserted.

Type Parameters

T

The type of the ICacheableAsyncResultFilter.

InsertFilter<T, TOptions>(IList<ICacheableAsyncResultFilter>, int, Action<TOptions>)

Inserts a cache related HTTP filter to the list at the specified index.

public static void InsertFilter<T, TOptions>(this IList<ICacheableAsyncResultFilter> filters, int index, Action<TOptions> setup = null) where T : ICacheableAsyncResultFilter where TOptions : class, IParameterObject, new()

Parameters

filters IList<ICacheableAsyncResultFilter>

The list of cache related HTTP filters.

index int

The zero-based index at which a HTTP related filter should be inserted.

setup Action<TOptions>

The Action<T> which may be configured.

Type Parameters

T

The type of the ICacheableAsyncResultFilter.

TOptions

The type of delegate setup to configure T.