Table of Contents

Class AsyncMemoizationDictionary<TInput, TOutput>

Namespace
Garyon.Objects
Assembly
Garyon.dll

Encapsulates a memoization dictionary for caching outputs of an async function.

public sealed class AsyncMemoizationDictionary<TInput, TOutput> where TInput : notnull

Type Parameters

TInput
TOutput
Inheritance
AsyncMemoizationDictionary<TInput, TOutput>
Inherited Members
Extension Methods

Remarks

This uses a ConcurrentDictionary<TKey, TValue> under the hood, which is initialized with a given concurrency level and capacity in its constructor.

Constructors

AsyncMemoizationDictionary(Func<TInput, ValueTask<TOutput>>, int, int)

Encapsulates a memoization dictionary for caching outputs of an async function.

public AsyncMemoizationDictionary(Func<TInput, ValueTask<TOutput>> func, int concurrencyLevel, int capacity = 64)

Parameters

func Func<TInput, ValueTask<TOutput>>

The function that computes the outputs.

concurrencyLevel int

The concurrency level to use for the cache dictionary, which should match the expected average concurrent readers of the cache. This matches the parameter in the constructor of ConcurrentDictionary<TKey, TValue>.

capacity int

The initial capacity of the dictionary.

Remarks

This uses a ConcurrentDictionary<TKey, TValue> under the hood, which is initialized with a given concurrency level and capacity in its constructor.

Methods

Clear()

Clears the cache.

public void Clear()

Get(TInput)

Gets the value of the given input. If the value has not been computed before, it is computed and stored into the dictionary for future retrievals. Otherwise, it's fetched directly from the dictionary.

public ValueTask<TOutput> Get(TInput input)

Parameters

input TInput

The input to the function.

Returns

ValueTask<TOutput>

The output of the function that was initialized, either cached or computed.