Table of Contents

Interface IDataLoader

Namespace
GreenDonut
Assembly
GreenDonut.dll

A DataLoader creates a public API for loading data from a particular data back-end with unique keys such as the id column of a SQL table or document name in a MongoDB database, given a batch loading function. -- facebook

Each DataLoader instance contains a unique memoized cache. Use caution when used in long-lived applications or those which serve many users with different access permissions and consider creating a new instance per web request. -- facebook

public interface IDataLoader
Extension Methods

Methods

Clear()

Empties the complete cache.

void Clear()

LoadAsync(IReadOnlyCollection<object>, CancellationToken)

Loads multiple values by keys. This call may return cached values and enqueues requests which were not cached for batching if enabled.

Task<IReadOnlyList<object?>> LoadAsync(IReadOnlyCollection<object> keys, CancellationToken cancellationToken = default)

Parameters

keys IReadOnlyCollection<object>

A list of unique keys.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<IReadOnlyList<object>>

A list of values in the same order as the provided keys.

Exceptions

ArgumentNullException

Throws if keys is null.

LoadAsync(object, CancellationToken)

Loads a single value by key. This call may return a cached value or enqueues this single request for batching if enabled.

Task<object?> LoadAsync(object key, CancellationToken cancellationToken = default)

Parameters

key object

A unique key.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<object>

A single result which may contain a value or information about the error which may occurred during the call.

Exceptions

ArgumentNullException

Throws if key is null.

Remove(object)

Removes a single entry from the cache.

void Remove(object key)

Parameters

key object

A cache entry key.

Exceptions

ArgumentNullException

Throws if key is null.

Set(object, Task<object?>)

Adds a new entry to the cache if not already exists.

void Set(object key, Task<object?> value)

Parameters

key object

A cache entry key.

value Task<object>

A cache entry value.

Exceptions

ArgumentNullException

Throws if key is null.

ArgumentNullException

Throws if value is null.