Class LookupCache<K, T>
Cache optimized for concurrent lock free lookups (read).
public class LookupCache<K, T> : ICache<K, T> where K : notnull where T : class
Type Parameters
KT
- Inheritance
-
LookupCache<K, T>
- Implements
-
ICache<K, T>
- Inherited Members
- Extension Methods
Remarks
Concurrent writes are supported but incur more overhead...
Constructors
LookupCache()
Default ctor.
public LookupCache()
LookupCache(IEnumerable<KeyValuePair<K, T>>)
Default ctor.
public LookupCache(IEnumerable<KeyValuePair<K, T>> data)
Parameters
dataIEnumerable<KeyValuePair<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
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.