DefaultModelCache<T, TInput, TOutput>
Models & Types · AiDotNet.Caching
Provides a default implementation of model caching for optimization step data.
Implements: IModelCache<T, TInput, TOutput>
For Beginners
A model cache is like a storage box that keeps track of the progress made during machine learning model training.
When training a machine learning model, the system makes many small adjustments (optimization steps) to improve the model’s accuracy. Each step produces important information about the model’s current state.
This cache stores that information for each step, allowing the training process to:
- Resume training from where it left off if interrupted
- Avoid repeating calculations that were already done
- Keep track of how the model is improving over time
Think of it like saving your progress in a video game, so you don’t have to start from the beginning if you need to take a break.
Constructors
| Constructor | Summary |
|---|---|
DefaultModelCache() |
Initializes a new cache with the recommended defaults: DefaultCapacity entries, DefaultEvictionPolicy eviction. |
DefaultModelCache(int capacity) |
Initializes a new cache that retains at most capacity distinct entries, evicting with the recommended DefaultEvictionPolicy. |
DefaultModelCache(int capacity, CacheEvictionPolicy evictionPolicy, bool enabled) |
Initializes a new cache that retains at most capacity distinct entries, evicting per evictionPolicy. |
Properties
| Property | Summary |
|---|---|
CacheEvictionPolicy EvictionPolicy { get; } |
The policy used to choose the eviction victim once the cache is full. |
bool Enabled { get; } |
Whether the cache actually stores entries (false = disabled pass-through). |
int Capacity { get; } |
Maximum number of distinct keys retained before an entry is evicted. |
Methods
| Method | Summary |
|---|---|
IModelCache<T, TInput, TOutput> CreateEmptyCopy() |
|
OptimizationStepData<T, TInput, TOutput> GetCachedStepData(string key) |
Retrieves cached optimization step data using the specified key. |
string GenerateCacheKey(IFullModel<T, TInput, TOutput> solution, OptimizationInputData<T, TInput, TOutput> inputData) |
Generates a deterministic cache key based on the solution model and input data using SHA-256 hashing. |
void CacheStepData(string key, OptimizationStepData<T, TInput, TOutput> stepData) |
Stores optimization step data in the cache with the specified key. |
void ClearCache() |
Removes all cached optimization step data from the cache. |
Fields
| Field | Summary |
|---|---|
CacheEvictionPolicy DefaultEvictionPolicy |
Recommended default eviction policy: oldest-inserted first. |
int DefaultCapacity |
Default maximum number of distinct step-data entries retained before eviction. |