CacheableFactory Class
Definition
- Namespace
- Cuemon.AspNetCore.Mvc
- Assemblies
- Cuemon.AspNetCore.Mvc.dll
Provides access to factory methods for creating and configuring objects implementing the ICacheableObjectResult interface.
public static class CacheableFactory
- Inheritance
-
objectCacheableFactory
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
| Name | Description |
|---|---|
| CreateHttpEntityTag<T>(T, Action<ContentBasedObjectResultOptions<T>>) | Encapsulates the specified |
| CreateHttpLastModified<T>(T, Action<TimeBasedObjectResultOptions<T>>) | Encapsulates the specified |
| Create<T>(T, Action<CacheableObjectResultOptions<T>>) | Encapsulates the specified |