Class SimpleCache<TKey, KValue>
Simple cache implementation.
Inherited Members
Namespace: Evergine.Common.Collections
Assembly: Evergine.Common.dll
Syntax
public class SimpleCache<TKey, KValue>
Type Parameters
Name | Description |
---|---|
TKey | The cache key. |
KValue | The cache value. |
Constructors
SimpleCache()
Initializes a new instance of the SimpleCache<TKey, KValue> class.
Declaration
public SimpleCache()
Properties
Expiration
Gets or sets the cache expiration time.
Declaration
public long Expiration { get; set; }
Property Value
Type | Description |
---|---|
long |
Methods
CheckConsistency(Action<TKey>)
Checks cache consistency. Remove unused elements.
Declaration
public void CheckConsistency(Action<TKey> itemRemovedFunc = null)
Parameters
Type | Name | Description |
---|---|---|
Action<TKey> | itemRemovedFunc | Method invoked when an item is removed. |
GetOrAdd(TKey, Func<TKey, KValue>)
Gets an item of the cache from its key. And if it doesn't exist, a it adds one to the cache.
Declaration
public KValue GetOrAdd(TKey key, Func<TKey, KValue> createFunction = null)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to search. |
Func<TKey, KValue> | createFunction | The Create function in case the element is not in the cache. |
Returns
Type | Description |
---|---|
KValue | The key item. If it doesn't exist in the cache, a new one is created and added. |
GetOrAdd<TContext>(TKey, TContext, Func<TKey, TContext, KValue>)
Gets an item of the cache from its key. And if it doesn't exist, a it adds one to the cache.
Declaration
public KValue GetOrAdd<TContext>(TKey key, TContext context, Func<TKey, TContext, KValue> createFunction = null)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to search. |
TContext | context | The create function context. |
Func<TKey, TContext, KValue> | createFunction | The Create function in case the element is not in the cache. |
Returns
Type | Description |
---|---|
KValue | The key item. If it doesn't exist in the cache, a new one is created and added. |
Type Parameters
Name | Description |
---|---|
TContext | The createFunction context. |
UpdateOrAdd(TKey, Func<KValue>)
Gets an item of the cache from its key. And if it doesn't exist, a it adds one to the cache.
Declaration
public KValue UpdateOrAdd(TKey key, Func<KValue> createFunction = null)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to search. |
Func<KValue> | createFunction | The Create function in case the element is not in the cache. |
Returns
Type | Description |
---|---|
KValue | The key item. If it doesn't exist in the cache, a new one is created and added. |