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