Table of Contents

Class CacheableFactory

Namespace
Cuemon.AspNetCore.Mvc
Assembly
Cuemon.AspNetCore.Mvc.dll

Provides access to factory methods for creating and configuring objects implementing the ICacheableObjectResult interface.

public static class CacheableFactory
Inheritance
CacheableFactory

Examples

The following example demonstrates how to create cacheable response objects using CacheableFactory.

using System;
using System.Security.Cryptography;
using System.Text;
using Cuemon.AspNetCore.Mvc;

namespace MyApp.Examples;

public static class CacheableFactoryExample
{
    public static void Demonstrate()
    {
        var content = "hello-world";

        var lastModified = CacheableFactory.CreateHttpLastModified(content, o =>
        {
            o.TimestampProvider = _ => DateTime.UtcNow;
            o.ChangedTimestampProvider = _ => DateTime.UtcNow;
        });

        var entityTag = CacheableFactory.CreateHttpEntityTag(content, o =>
        {
            o.ChecksumProvider = value => SHA256.HashData(Encoding.UTF8.GetBytes(value));
            o.WeakChecksumProvider = _ => false;
        });

        var combined = CacheableFactory.Create(content, o =>
        {
            o.TimestampProvider = _ => DateTime.UtcNow;
            o.ChecksumProvider = value => SHA256.HashData(Encoding.UTF8.GetBytes(value));
            o.ChangedTimestampProvider = _ => DateTime.UtcNow;
            o.WeakChecksumProvider = _ => false;
        });

        Console.WriteLine(lastModified is ICacheableObjectResult);
        Console.WriteLine(entityTag is ICacheableObjectResult);
        Console.WriteLine(combined is ICacheableObjectResult);
    }
}

Methods

CreateHttpEntityTag<T>(T, Action<ContentBasedObjectResultOptions<T>>)

Encapsulates the specified instance within an integrity based object that is processed by an HTTP ETag filter implementation.

public static ICacheableObjectResult CreateHttpEntityTag<T>(T instance, Action<ContentBasedObjectResultOptions<T>> setup)

Parameters

instance T

The instance to make cacheable.

setup Action<ContentBasedObjectResultOptions<T>>

The ContentBasedObjectResultOptions<T> that needs to be configured.

Returns

ICacheableObjectResult

An ICacheableObjectResult implementation.

Type Parameters

T

The type of the object to make cacheable.

See Also
CacheableObjectResult<T>

CreateHttpLastModified<T>(T, Action<TimeBasedObjectResultOptions<T>>)

Encapsulates the specified instance within a timestamp based object that is processed by a Last-Modified filter implementation.

public static ICacheableObjectResult CreateHttpLastModified<T>(T instance, Action<TimeBasedObjectResultOptions<T>> setup)

Parameters

instance T

The instance to make cacheable.

setup Action<TimeBasedObjectResultOptions<T>>

The TimeBasedObjectResultOptions<T> that needs to be configured.

Returns

ICacheableObjectResult

An ICacheableObjectResult implementation.

Type Parameters

T

The type of the object to make cacheable.

See Also
CacheableObjectResult<T>

Create<T>(T, Action<CacheableObjectResultOptions<T>>)

Encapsulates the specified instance within a timestamp and integrity based object that is processed by both HTTP Last-Modified and HTTP ETag filters implementation.

public static ICacheableObjectResult Create<T>(T instance, Action<CacheableObjectResultOptions<T>> setup)

Parameters

instance T

The instance to make cacheable.

setup Action<CacheableObjectResultOptions<T>>

The CacheableObjectResultOptions<T> that needs to be configured.

Returns

ICacheableObjectResult

An ICacheableObjectResult implementation.

Type Parameters

T

The type of the object to make cacheable.

See Also
CacheableObjectResult<T>