CacheEvictionStrategy
CacheEvictionStrategy selects the algorithm DynamicWhere.ex uses to evict entries from its internal reflection cache when a store reaches MaxCacheSize. It lives in DynamicWhere.ex.Optimization.Cache.Config.
Values
| Value | Description |
|---|---|
FIFO | First-In-First-Out. Predictable, minimal overhead — no per-access bookkeeping. |
LRU | Least Recently Used. Optimizes for temporal locality. (Default) |
LFU | Least Frequently Used. Optimizes for access-frequency patterns. |
Trade-offs
| Strategy | Best for | Overhead | Tracking |
|---|---|---|---|
FIFO | Testing, debugging, predictable behavior. Easy to reason about. | Minimal — only insertion order. | None per-access. |
LRU | Recent-access-heavy workloads (admin dashboards, paginated browsing). Default for a reason — usually the right answer. | Light — timestamp per access. | EnableLruTracking auto-enabled. |
LFU | Hot-set workloads where the same types/paths are hit repeatedly (high-frequency endpoints, type catalogs). | Light — counter per access. | EnableLfuTracking auto-enabled. |
Note
Tracking flags are managed automatically based on the strategy you select. You normally don't need to touch
EnableLruTracking or EnableLfuTracking directly.C# usage
Builder pattern:
using DynamicWhere.ex.Optimization.Cache.Source;
using DynamicWhere.ex.Optimization.Cache.Config;
CacheExpose.Configure(options =>
{
options.MaxCacheSize = 2000;
options.LeastUsedThreshold = 20;
options.EvictionStrategy = CacheEvictionStrategy.LFU;
});Direct object:
CacheExpose.Configure(new CacheOptions
{
MaxCacheSize = 3000,
LeastUsedThreshold = 15,
MostUsedThreshold = 85,
EvictionStrategy = CacheEvictionStrategy.LRU
});Presets that use each strategy
| Preset | Strategy |
|---|---|
ForHighMemoryEnvironment() | LRU |
ForLowMemoryEnvironment() | LFU |
ForDevelopment() | FIFO |
ForHighFrequencyAccess() | LFU |
ForTemporalAccess() | LRU |
Related
- CacheOptions → all tunable knobs and defaults.
- Configuration presets → ready-made configurations for common workloads.
- CacheMemoryType → identifies the three stores the strategy applies to.
- Cache architecture → full system overview.