Table of Contents

Class BasicCache<K, T>

Namespace
Tlabs.Misc
Assembly
Tlabs.Core.dll

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

K
T
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

init IDictionary<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

key K

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

key K
getValue Func<T>

Property Value

T

The value for the key in the cache or the value returned from getValue.

Methods

Dispose()

public void Dispose()

Dispose(bool)

Do dispose

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Evict(K)

Evict entry with key.

public T? Evict(K key)

Parameters

key K

Returns

T

Evicted entry or null if no value cached for key.