Table of Contents

CacheableObjectResultOptions<T> Class

Definition

Namespace
Cuemon.AspNetCore.Mvc
Assemblies
Cuemon.AspNetCore.Mvc.dll
Source
src/Cuemon.AspNetCore.Mvc/CacheableObjectResultOptions.cs

Specifies options that is related to the ICacheableObjectResult interface.

public class CacheableObjectResultOptions<T> : IContentBasedObjectResultOptions<T>, ITimeBasedObjectResultOptions<T>, IValidatableParameterObject, IParameterObject

Type Parameters

T
Inheritance
CacheableObjectResultOptions<T>
Implements

Examples

The following example demonstrates how to configure to enable HTTP caching (ETag and Last-Modified) for a response model.

// Program.cs
using System;
using System.Security.Cryptography;
using System.Text;
using Cuemon.AspNetCore.Mvc;

var options = new CacheableObjectResultOptions<string>
{
    ChecksumProvider = value => SHA256.HashData(Encoding.UTF8.GetBytes(value)),
    WeakChecksumProvider = _ => false,
    TimestampProvider = _ => DateTime.UtcNow,
    ChangedTimestampProvider = _ => DateTime.UtcNow
};

options.ValidateOptions();

var data = "hello-world";
byte[] checksum = options.ChecksumProvider(data);
Console.WriteLine($"Checksum length: {checksum.Length}"); // 32 bytes (SHA256)
Console.WriteLine($"Created: {options.TimestampProvider(data)}");

Constructors

Name Description
CacheableObjectResultOptions()

Initializes a new instance of the CacheableObjectResultOptions<T> class.

Properties

Name Description
ChangedTimestampProvider

Gets or sets the function delegate that resolves a timestamp from when the specified T was last modified, expressed as the Coordinated Universal Time (UTC).

ChecksumProvider

Gets or sets the function delegate that resolves a checksum defining the data integrity of the specified T.

TimestampProvider

Gets or sets the function delegate that resolves a timestamp from when the specified T was first created, expressed as the Coordinated Universal Time (UTC).

WeakChecksumProvider

Gets or sets the function delegate that resolves a value hinting whether the specified ChecksumProvider resembles a weak or a strong checksum strength.

Methods

Name Description
ValidateOptions()

Determines whether the public read-write properties of this instance are in a valid state.

See Also