Class BasicCache<K, T>
Basic cache supporting concurrent access with balanced read/write locking.
public class BasicCache<K, T> : IDisposable, ICache<K, T> where K : notnull where T : class
Type Parameters
KT
- Inheritance
-
BasicCache<K, T>
- Implements
-
ICache<K, T>
- Inherited Members
- Extension Methods
Constructors
BasicCache()
Default ctor.
public BasicCache()
BasicCache(IDictionary<K, T>)
Ctor to initialize from init.
public BasicCache(IDictionary<K, T> init)
Parameters
initIDictionary<K, T>
Properties
Entries
Cached entries.
public IEnumerable<KeyValuePair<K, T>> Entries { get; }
Property Value
- IEnumerable<KeyValuePair<K, T>>
Snapshot of the currently cached entries.
this[K]
Get or set value with key.
public T? this[K key] { get; set; }
Parameters
keyK
Property Value
- T
Cached entry or null if no value cached for
key.
this[K, Func<T>]
Gets an already cached value for the given key or if no cached value exists adds the value returned from getValue.
public T this[K key, Func<T> getValue] { get; }
Parameters
keyKgetValueFunc<T>
Property Value
- T
The value for the
keyin the cache or the value returned fromgetValue.
Methods
Dispose()
public void Dispose()
Dispose(bool)
Do dispose
protected virtual void Dispose(bool disposing)
Parameters
disposingbool
Evict(K)
Evict entry with key.
public T? Evict(K key)
Parameters
keyK
Returns
- T
Evicted entry or null if no value cached for
key.