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
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.
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
Return the number of items in the cache.
Cache name.
Stores the collection options (expiry date and capacity)
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.
Clear ()
Remove all items from the cache.
Collect ()
Remove expired items from the cache.
Expire (<TKey> key, TimeSpan time)
Override the expiry time for an item from the cache, specifed by key.
Parameters
Name Type
key <TKey>
time TimeSpan
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.
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 itemReader). If the cache item expiry date has been reached, this function removes it from the cache and returns null.
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.
Remove (<TKey> key)
Remove an item from the cache, specified by key.
Parameters
Name Type
key <TKey>