Nucleus .Net Core CMS

Models.Cache.CacheCollection<TKey, TModel> Class

Namespace: Nucleus.Abstractions.Models.Cache
Assembly: Nucleus.Abstractions.dll
Stores a collection of cached entities keys and values. Provides operations to populate and retrieve, remove and clear items the cache.
Type Parameters
TKey Key type
TModel Item type

Remarks

Items are wrapped in a CacheItem object in order to apply a cache item expiry date. This class has no Add method, instead the Get method has a Func parameter which contains an delegate which is invoked to get an instance of the item, if it is not already present in the cache.

Constructor

Nucleus.Abstractions.Models.Cache.CacheCollection<TKey, TModel> Constructor

Nucleus.Abstractions.Models.Cache.CacheCollection<TKey, TModel> (String name, ILogger<ICacheManager> logger, CacheOption options)
Initialize a new instance of the CacheCollection class using the options provided.
Parameters
Name Type
name String
logger Microsoft.Extensions.Logging.ILogger<Nucleus.Abstractions.Managers.ICacheManager>
options Nucleus.Abstractions.Models.Configuration.CacheOption

Methods

Get (<TKey,TKey>) Method

Get (<TKey, TKey> itemReader)
Get the item from the cache with the specified key, or if it not present in the cache, read it (using itemReader), add it to the cache and return it.
Parameters
Name Type
key <TKey>
itemReader Func<TKey>
Returns
The item that matches the specified key.

GetAsync (<TKey,TKey>) Method

GetAsync (<TKey, TKey> itemReader)
Get the item from the cache with the specified key, or if it not present in the cache, read it (using itemReader), add it to the cache and return it.
Parameters
Name Type
key <TKey>
itemReader Func<TKey>
Returns
The item that matches the specified key.

Get (<TKey>) Method

Get (<TKey> key)
Get the item from the cache with the specified key.
Parameters
Name Type
key <TKey>
Returns
The item with the specified key, or null if it not in the cache, or the cache item has expired.
Remarks
This function is private. Callers should use Get(TKey id, Func<TKey, TModel> itemReader). If the cache item expiry date has been reached, this function removes it from the cache and returns null.

Add (<TKey,TModel>) Method

Add (<TKey, TModel> item)
Add the specified key/item to the cache.
Parameters
Name Type
key <TKey>
item <TModel>
Remarks
This function is private. Items are added to the cache by the .Get function. If the cache reaches capacity, the oldest cache item is removed.

Remove (<TKey>) Method

Remove (<TKey> key)
Remove an item from the cache, specifed by key.
Parameters
Name Type
key <TKey>

Clear

Clear ()
Remove all items from the cache.

Collect

Collect ()
Remove expired items from the cache.