Table of Contents

Class CacheModel

Namespace
OpenSettings.Models
Assembly
OpenSettings.dll

Represents a model for organizing and tracking memory cache keys.

This class is designed to track cache keys in a more organized manner, supporting operations like managing cache key parts and reusing cache details efficiently.

The CacheModel class provides functionality for concatenating cache key parts, storing cache keys, and organizing them using a concurrent dictionary for better performance and thread safety.

public class CacheModel
Inheritance
CacheModel
Inherited Members
Extension Methods

Constructors

CacheModel(object)

public CacheModel(object key)

Parameters

key object

CacheModel(object, DateTimeOffset?)

Initializes a new instance of the CacheModel class with the specified key and absolute expiration date.

public CacheModel(object key, DateTimeOffset? absoluteExpiration)

Parameters

key object

The key used to identify the cache entry.

absoluteExpiration DateTimeOffset?

The absolute expiration date after which the cache entry will expire.

CacheModel(object, DateTimeOffset?, TimeSpan?)

Initializes a new instance of the CacheModel class with the specified key, absolute expiration date, and sliding expiration time.

public CacheModel(object key, DateTimeOffset? absoluteExpiration, TimeSpan? slidingExpiration)

Parameters

key object

The key used to identify the cache entry.

absoluteExpiration DateTimeOffset?

The absolute expiration date after which the cache entry will expire.

slidingExpiration TimeSpan?

The sliding expiration time after which the cache entry will expire if not accessed.

CacheModel(object, TimeSpan?)

Initializes a new instance of the CacheModel class with the specified key and relative expiration time.

public CacheModel(object key, TimeSpan? absoluteExpirationRelativeToNow)

Parameters

key object

The key used to identify the cache entry.

absoluteExpirationRelativeToNow TimeSpan?

The relative expiration time after which the cache entry will expire.

CacheModel(object, TimeSpan?, TimeSpan?)

Initializes a new instance of the CacheModel class with the specified key and relative expiration time, and sliding expiration time.

public CacheModel(object key, TimeSpan? absoluteExpirationRelativeToNow, TimeSpan? slidingExpiration)

Parameters

key object

The key used to identify the cache entry.

absoluteExpirationRelativeToNow TimeSpan?

The relative expiration time after which the cache entry will expire.

slidingExpiration TimeSpan?

The sliding expiration time after which the cache entry will expire if not accessed.

CacheModel(params object[])

Initializes a new instance of the CacheModel class with the specified key parts.

public CacheModel(params object[] keyParts)

Parameters

keyParts object[]

An array of key parts used to identify the cache entry.

Exceptions

ArgumentNullException

Thrown if the keyParts is null.

CacheModel(object[], DateTimeOffset?)

Initializes a new instance of the CacheModel class with the specified key parts and absolute expiration date.

public CacheModel(object[] keyParts, DateTimeOffset? absoluteExpiration)

Parameters

keyParts object[]

An array of key parts used to identify the cache entry.

absoluteExpiration DateTimeOffset?

The absolute expiration date after which the cache entry will expire.

CacheModel(object[], DateTimeOffset?, TimeSpan?)

Initializes a new instance of the CacheModel class with the specified key parts, absolute expiration date, and sliding expiration time.

public CacheModel(object[] keyParts, DateTimeOffset? absoluteExpiration, TimeSpan? slidingExpiration)

Parameters

keyParts object[]

An array of key parts used to identify the cache entry.

absoluteExpiration DateTimeOffset?

The absolute expiration date after which the cache entry will expire.

slidingExpiration TimeSpan?

The sliding expiration time after which the cache entry will expire if not accessed.

CacheModel(object[], TimeSpan?)

Initializes a new instance of the CacheModel class with the specified key parts and relative expiration time.

public CacheModel(object[] keyParts, TimeSpan? absoluteExpirationRelativeToNow)

Parameters

keyParts object[]

An array of key parts used to identify the cache entry.

absoluteExpirationRelativeToNow TimeSpan?

The relative expiration time after which the cache entry will expire.

CacheModel(object[], TimeSpan?, TimeSpan?)

Initializes a new instance of the CacheModel class with the specified key parts, relative expiration time, and sliding expiration time.

public CacheModel(object[] keyParts, TimeSpan? absoluteExpirationRelativeToNow, TimeSpan? slidingExpiration)

Parameters

keyParts object[]

An array of key parts used to identify the cache entry.

absoluteExpirationRelativeToNow TimeSpan?

The relative expiration time after which the cache entry will expire.

slidingExpiration TimeSpan?

The sliding expiration time after which the cache entry will expire if not accessed.

Properties

AbsoluteExpiration

Gets or sets an absolute expiration date for the cache entry.

public DateTimeOffset? AbsoluteExpiration { get; }

Property Value

DateTimeOffset?

AbsoluteExpirationRelativeToNow

Gets or sets an absolute expiration time, relative to now.

public TimeSpan? AbsoluteExpirationRelativeToNow { get; }

Property Value

TimeSpan?

ExpirationTokens

Gets the Microsoft.Extensions.Primitives.IChangeToken instances which cause the cache entry to expire

public IList<IChangeToken> ExpirationTokens { get; }

Property Value

IList<IChangeToken>

Key

public object Key { get; }

Property Value

object

PostEvictionCallbacks

Gets or sets the callbacks will be fired after the cache entry is evicted from the cache.

public IList<PostEvictionCallbackRegistration> PostEvictionCallbacks { get; }

Property Value

IList<PostEvictionCallbackRegistration>

Priority

Gets or sets the priority for keeping the cache entry in the cache during a memory pressure triggered cleanup. The default is Microsoft.Extensions.Caching.Memory.CacheItemPriority.Normal.

public CacheItemPriority Priority { get; set; }

Property Value

CacheItemPriority

SlidingExpiration

Gets or sets how long a cache entry can be inactive (e.g. not accessed) before it will be removed. This will not extend the entry lifetime beyond the absolute expiration (if set).

public TimeSpan? SlidingExpiration { get; }

Property Value

TimeSpan?

Methods

Delete(IDistributedCache)

Deletes a specific cache entry from distributed cache.

The Delete(IDistributedCache) method removes the cache entry corresponding to the cache key from the distributed cache.

public void Delete(IDistributedCache distributedCache)

Parameters

distributedCache IDistributedCache

The IDistributedCache instance used to remove the cache entry.

Delete(IMemoryCache)

Deletes a specific cache entry from memory cache.

The Delete(IMemoryCache) method removes the cache entry corresponding to the cache key from the memory cache.

public void Delete(IMemoryCache memoryCache)

Parameters

memoryCache IMemoryCache

The IMemoryCache instance used to remove the cache entry.

Delete(IMemoryCache, Func<object, bool>)

Deletes cache entries from memory cache based on the provided predicate.

The Delete(IMemoryCache, Func<object, bool>) method will evaluate the given predicate to filter cache keys, and removes the corresponding cache entries from the memory cache.

public void Delete(IMemoryCache memoryCache, Func<object, bool> predicate)

Parameters

memoryCache IMemoryCache

The IMemoryCache instance used to remove the cache entries.

predicate Func<object, bool>

A function used to evaluate and filter cache keys to be deleted.

Exceptions

ArgumentNullException

Thrown if predicate is null.

DeleteAll(IMemoryCache)

Deletes all cache entries from memory cache.

The DeleteAll(IMemoryCache) method removes all cache entries from the memory cache associated with the current cache model.

public void DeleteAll(IMemoryCache memoryCache)

Parameters

memoryCache IMemoryCache

The IMemoryCache instance used to remove all cache entries.

DeleteAllAsync(IDistributedCache)

Deletes all cache entries from distributed cache asynchronously.

The DeleteAllAsync(IDistributedCache) method removes all cache entries from the distributed cache associated with the current cache model asynchronously.

public Task DeleteAllAsync(IDistributedCache distributedCache)

Parameters

distributedCache IDistributedCache

The IDistributedCache instance used to remove all cache entries.

Returns

Task

A task representing the asynchronous operation.

DeleteAsync(IDistributedCache)

Deletes a specific cache entry from distributed cache asynchronously.

The DeleteAsync(IDistributedCache) method removes the cache entry corresponding to the cache key from the distributed cache asynchronously.

public Task DeleteAsync(IDistributedCache distributedCache)

Parameters

distributedCache IDistributedCache

The IDistributedCache instance used to remove the cache entry.

Returns

Task

A task representing the asynchronous operation.

DeleteIfStartsWith(IMemoryCache, params object[])

Deletes cache entries from memory cache if the cache key starts with the given key parts.

The DeleteIfStartsWith(IMemoryCache, params object[]) method removes cache entries whose keys match a given pattern that starts with the specified keyParts.

public void DeleteIfStartsWith(IMemoryCache memoryCache, params object[] keyParts)

Parameters

memoryCache IMemoryCache

The IMemoryCache instance used to remove the cache entries.

keyParts object[]

The parts of the key to match the cache keys starting with.

DeleteIfStartsWithAsync(IDistributedCache, CancellationToken, params object[])

Deletes cache entries from distributed cache asynchronously if the cache key starts with the given key parts.

The DeleteIfStartsWithAsync(IDistributedCache, CancellationToken, params object[]) method removes cache entries from the distributed cache that match a given pattern based on the keyParts. This operation is performed asynchronously.

public Task DeleteIfStartsWithAsync(IDistributedCache distributedCache, CancellationToken cancellationToken, params object[] keyParts)

Parameters

distributedCache IDistributedCache

The IDistributedCache instance used to remove the cache entries.

cancellationToken CancellationToken

A token used to cancel the asynchronous operation.

keyParts object[]

The parts of the key to match the cache keys starting with.

Returns

Task

A task representing the asynchronous operation.