Class CacheInvalidation
Represents a set of eviction and expiration details for a specific cache entry.
public class CacheInvalidation
- Inheritance
-
CacheInvalidation
Examples
The following example demonstrates how to use
using System;
using Cuemon.Runtime.Caching; // for CacheInvalidation
namespace MyApp.Examples;
public class CacheInvalidationExample
{
public void Demonstrate()
{
// Absolute expiration at a specific UTC time
var absolute = new CacheInvalidation(new DateTime(2025, 12, 31, 23, 59, 59, DateTimeKind.Utc));
Console.WriteLine(absolute.UseAbsoluteExpiration); // True
Console.WriteLine(absolute.AbsoluteExpiration); // 12/31/2025 23:59:59
Console.WriteLine(absolute.UseSlidingExpiration); // False
Console.WriteLine(absolute.UseDependency); // False
// Sliding expiration (entry expires after 30 minutes of inactivity)
var sliding = new CacheInvalidation(TimeSpan.FromMinutes(30));
Console.WriteLine(sliding.UseSlidingExpiration); // True
Console.WriteLine(sliding.SlidingExpiration); // 00:30:00
Console.WriteLine(sliding.UseAbsoluteExpiration); // False
}
}
Constructors
CacheInvalidation(IEnumerable<IDependency>)
Initializes a new instance of the CacheInvalidation class.
public CacheInvalidation(IEnumerable<IDependency> dependencies)
Parameters
dependenciesIEnumerable<IDependency>A sequence of IDependency implementations that monitors changes in the state of the data which a cache entry depends on. If a state change is registered, the cached value becomes invalid and is removed from the cache.
CacheInvalidation(DateTime)
Initializes a new instance of the CacheInvalidation class.
public CacheInvalidation(DateTime absoluteExpiration)
Parameters
absoluteExpirationDateTimeThe absolute expiration date time value from when the cached value becomes invalid and is removed from the cache.
CacheInvalidation(TimeSpan)
Initializes a new instance of the CacheInvalidation class.
public CacheInvalidation(TimeSpan slidingExpiration)
Parameters
slidingExpirationTimeSpanThe sliding expiration time from when the cached value becomes invalid and is removed from the cache.
Properties
AbsoluteExpiration
Gets the UTC absolute expiration date time value of a CacheEntry.
public DateTime? AbsoluteExpiration { get; }
Property Value
- DateTime?
The UTC absolute expiration date time value of a CacheEntry.
Dependencies
Gets a sequence of objects implementing the IDependency interface assigned to a CacheEntry.
public IEnumerable<IDependency> Dependencies { get; }
Property Value
- IEnumerable<IDependency>
A sequence of objects implementing the IDependency interface assigned to a CacheEntry.
SlidingExpiration
Gets the sliding expiration time of a CacheEntry.
public TimeSpan? SlidingExpiration { get; }
Property Value
- TimeSpan?
The sliding expiration time of a CacheEntry.
UseAbsoluteExpiration
Gets a value indicating whether a CacheEntry should use AbsoluteExpiration property for cache invalidation.
public bool UseAbsoluteExpiration { get; }
Property Value
- bool
trueif a CacheEntry should use AbsoluteExpiration property for cache invalidation; otherwise,false.
UseDependency
Gets a value indicating whether this CacheEntry is relying on an IDependency implementation for cache invalidation.
public bool UseDependency { get; }
Property Value
- bool
trueif a CacheEntry is relying on an IDependency implementation for cache invalidation; otherwise,false.
UseSlidingExpiration
Gets a value indicating whether a CacheEntry should use SlidingExpiration property for cache invalidation.
public bool UseSlidingExpiration { get; }
Property Value
- bool
trueif a CacheEntry should use SlidingExpiration property for cache invalidation; otherwise,false.