Interface IDataLoader<TKey, TValue>
- 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<in TKey, TValue> : IDataLoader where TKey : notnull
Type Parameters
TKey
A key type.
TValue
A value type.
- Inherited Members
- Extension Methods
Methods
LoadAsync(IReadOnlyCollection<TKey>, 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<TValue>> LoadAsync(IReadOnlyCollection<in TKey> keys, CancellationToken cancellationToken = default)
Parameters
keys
IReadOnlyCollection<TKey>A list of unique keys.
cancellationToken
CancellationTokenA cancellation token.
Returns
- Task<IReadOnlyList<TValue>>
A list of values in the same order as the provided keys.
Exceptions
- ArgumentNullException
Throws if
keys
isnull
.
LoadAsync(TKey, CancellationToken)
Loads a single value by key. This call may return a cached value or enqueues this single request for batching if enabled.
Task<TValue> LoadAsync(TKey key, CancellationToken cancellationToken = default)
Parameters
key
TKeyA unique key.
cancellationToken
CancellationTokenA cancellation token.
Returns
- Task<TValue>
A single result which may contain a value or information about the error which may occurred during the call.
Exceptions
- ArgumentNullException
Throws if
key
isnull
.
Remove(TKey)
Removes a single entry from the cache.
void Remove(TKey key)
Parameters
key
TKeyA cache entry key.
Exceptions
- ArgumentNullException
Throws if
key
isnull
.
Set(TKey, Task<TValue>)
Adds a new entry to the cache if not already exists.
void Set(TKey key, Task<TValue> value)
Parameters
key
TKeyA cache entry key.
value
Task<TValue>A cache entry value.
Exceptions
- ArgumentNullException
Throws if
key
isnull
.- ArgumentNullException
Throws if
value
isnull
.