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 |
Constructor
CacheCollection<TKey, TModel>
(String, ILogger<ICacheManager>, CacheOption) Constructor
CacheCollection<TKey, TModel> (String name, ILogger<ICacheManager> logger, CacheOption options)
Initialize a new instance of the CacheCollection class using the options provided.
Properties
Count
Property
Return the number of items in the cache.
Name
Property
Cache name.
Options
Property
Stores the collection options (expiry date and capacity)
Methods
Add
(<TKey, TModel>) Method
Add (<TKey, TModel> item)
Add the specified key/item to the cache.
Parameters
| Name |
Type |
|
key
|
<TKey>
|
|
item
|
<TModel>
|
Clear
Clear ()
Remove all items from the cache.
Collect
Collect ()
Remove expired items from the cache.
Expire
(<TKey>, TimeSpan) Method
Expire (<TKey> key, TimeSpan time)
Override the expiry time for an item from the cache, specifed by key.
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.
Get
(<TKey>) Method
Get (<TKey> key)
Get the item from the cache with the specified key.
Returns
The item with the specified key, or null if it not in the cache, or the cache item has expired.
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.
Remove
(<TKey>) Method
Remove (<TKey> key)
Remove an item from the cache, specified by key.