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
TKeyA key type.
TValueA 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
keysIReadOnlyCollection<TKey>A list of unique keys.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<IReadOnlyList<TValue>>
A list of values in the same order as the provided keys.
Exceptions
- ArgumentNullException
Throws if
keysisnull.
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
keyTKeyA unique key.
cancellationTokenCancellationTokenA 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
keyisnull.
Remove(TKey)
Removes a single entry from the cache.
void Remove(TKey key)
Parameters
keyTKeyA cache entry key.
Exceptions
- ArgumentNullException
Throws if
keyisnull.
Set(TKey, Task<TValue>)
Adds a new entry to the cache if not already exists.
void Set(TKey key, Task<TValue> value)
Parameters
keyTKeyA cache entry key.
valueTask<TValue>A cache entry value.
Exceptions
- ArgumentNullException
Throws if
keyisnull.- ArgumentNullException
Throws if
valueisnull.