CachingDataLoader<TKey, TValue>

Models & Types · AiDotNet.Data.Loaders

Wraps data loading with an in-memory cache to avoid redundant I/O.

How It Works

Caches loaded batches by their key (typically batch index) to avoid reloading data that has already been seen. Useful when iterating over the same data multiple epochs or when random access patterns cause repeated reads.

Constructors

Constructor Summary
CachingDataLoader(CachingDataLoaderOptions options) Creates a new caching data loader.

Properties

Property Summary
double HitRatio { get; } Gets the cache hit ratio (hits / total requests).
int Count { get; } Gets the number of items currently in the cache.

Methods

Method Summary
TValue GetOrLoad(TKey key, Func<TKey, TValue> factory) Gets a value from the cache, or loads it using the provided factory.
bool Contains(TKey key) Checks if a key is in the cache.
bool Invalidate(TKey key) Invalidates a specific cache entry.
void Clear() Clears all cached items and resets statistics.