DynamicWhere.ex
DynamicWhere.exv3.4.0·docs

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

ValueDescription
FIFOFirst-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.
LRULeast Recently Used. Optimizes for temporal locality. (Default)
LFULeast Frequently Used. Optimizes for access-frequency patterns.

Trade-offs

StrategyBest forOverheadTracking
FIFOTesting 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.
LRURecent-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.
LFUHot-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

PresetStrategy
ForHighMemoryEnvironment()LRU
ForLowMemoryEnvironment()LFU
ForDevelopment()FIFO
ForHighFrequencyAccess()LFU
ForTemporalAccess()LRU