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.Enums.
Values
| Value | Description |
|---|---|
FIFO | First-In-First-Out in name only: eviction takes the first keys a ConcurrentDictionary enumerates, and that type keeps no insertion order — so the oldest entries are not the ones removed. 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 and debugging, when all you want is for the store to be trimmed — not for a particular entry to survive. | Minimal — no ordering data is kept. | None per-access. |
LRU | Recent-access-heavy workloads (admin dashboards, paginated browsing). Default for a reason — usually the right answer. | Light — timestamp per access. | Timestamps, because the strategy is LRU. EnableLruTracking is set to match, for reporting. |
LFU | Hot-set workloads where the same types/paths are hit repeatedly (high-frequency endpoints, type catalogs). | Light — counter per access. | Counters, because the strategy is LFU. EnableLfuTracking is set to match, for reporting. |
Note
EvictionStrategy alone decides what is tracked. The two flags only report that choice — auto-validation overwrites whatever you set, and with AutoValidateConfiguration = false a flag that does not match the strategy throws. Leave both alone.C# usage
Builder pattern:
using DynamicWhere.ex.Optimization.Cache.Source;
using DynamicWhere.ex.Optimization.Cache.Config;
using DynamicWhere.ex.Optimization.Cache.Enums;
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.