Class Cache<TKey, TValue>
Class for caching data.
Inheritance
System.Object
Cache<TKey, TValue>
Implements
ICache<TKey, TValue>
Namespace: Kros.Caching
Assembly: Kros.Utils.dll
Syntax
public class Cache<TKey, TValue> : ICache<TKey, TValue>
Type Parameters
Name | Description |
---|---|
TKey | The type of the key. |
TValue | The type of the value. |
Constructors
Cache()
Initializes a new instance of the Cache<TKey, TValue> class.
Declaration
public Cache()
Cache(IEqualityComparer<TKey>)
Initializes a new instance of the Cache<TKey, TValue> class.
Declaration
public Cache(IEqualityComparer<TKey> comparer)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEqualityComparer<TKey> | comparer | The System.Collections.Generic.IEqualityComparer<T> implementation to use when comparing keys. |
Properties
Count
Gets the count of cached data.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
Clear()
Clears the cache.
Declaration
public void Clear()
Get(TKey, Func<TValue>)
Gets the cached value by key.
Declaration
public TValue Get(TKey key, Func<TValue> factory)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key. |
System.Func<TValue> | factory | The factory for creating value, if doesn't exist in cahce. |
Returns
Type | Description |
---|---|
TValue | Value from Cache. |
Remarks
If value key doesn't exist in cache, then factory is use for creating value and value is set to cache.
Implements
See Also
ICache<TKey, TValue>