Class BatchDataLoader<TKey, TValue>
- Namespace
- GreenDonut
- Assembly
- GreenDonut.dll
The BatchDataLoader is the most commonly used variant of DataLoader and is optimized to fetch multiple items in a single batch from the database.
public abstract class BatchDataLoader<TKey, TValue> : DataLoaderBase<TKey, TValue>, IDataLoader<TKey, TValue>, IDataLoader, IDisposable where TKey : notnull
Type Parameters
TKey
A key type.
TValue
A value type.
- Inheritance
-
DataLoaderBase<TKey, TValue>BatchDataLoader<TKey, TValue>
- Implements
-
IDataLoader<TKey, TValue>
- Inherited Members
- Extension Methods
Constructors
BatchDataLoader(IBatchScheduler, DataLoaderOptions?)
Initializes a new instance of the BatchDataLoader<TKey, TValue> class.
protected BatchDataLoader(IBatchScheduler batchScheduler, DataLoaderOptions? options = null)
Parameters
batchScheduler
IBatchSchedulerA scheduler to tell the
DataLoader
when to dispatch buffered batches.options
DataLoaderOptionsAn options object to configure the behavior of this particular BatchDataLoader<TKey, TValue>.
Exceptions
- ArgumentNullException
Throws if
options
isnull
.
Methods
FetchAsync(IReadOnlyList<TKey>, Memory<Result<TValue>>, CancellationToken)
protected override sealed ValueTask FetchAsync(IReadOnlyList<TKey> keys, Memory<Result<TValue>> results, CancellationToken cancellationToken)
Parameters
keys
IReadOnlyList<TKey>results
Memory<Result<TValue>>cancellationToken
CancellationToken
Returns
LoadBatchAsync(IReadOnlyList<TKey>, CancellationToken)
Loads the data for a batch from the data source.
protected abstract Task<IReadOnlyDictionary<TKey, TValue>> LoadBatchAsync(IReadOnlyList<TKey> keys, CancellationToken cancellationToken)
Parameters
keys
IReadOnlyList<TKey>The keys that shall be fetched in a batch.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<IReadOnlyDictionary<TKey, TValue>>
Returns a dictionary holding the fetched data.