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
CancellationTokenA cancellation token.
Returns
- Task<IReadOnlyList<object>>
A list of values in the same order as the provided keys.
Exceptions
- ArgumentNullException
Throws if
keys
isnull
.
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
objectA unique key.
cancellationToken
CancellationTokenA 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
isnull
.
Remove(object)
Removes a single entry from the cache.
void Remove(object key)
Parameters
key
objectA cache entry key.
Exceptions
- ArgumentNullException
Throws if
key
isnull
.
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
key
isnull
.- ArgumentNullException
Throws if
value
isnull
.