DynamicWhere.ex
DynamicWhere.exv3.4.0·docs

CacheOptions

CacheOptions is the single configuration object for the reflection cache. Every tunable lives here — size caps, eviction algorithm, tracking toggles, and the auto-validation safety net.

Properties

PropertyTypeDefaultDescription
MaxCacheSizeint1000Maximum number of entries each store will hold before an eviction pass runs.
LeastUsedThresholdint25Percentage of entries to remove on a single eviction pass — the "least valuable" slice.
MostUsedThresholdint75Bookkeeping only — must equal 100 − LeastUsedThreshold, and Validate() corrects it when it does not. Eviction reads LeastUsedThreshold alone.
EvictionStrategyCacheEvictionStrategyLRUAlgorithm used to pick the least-valuable entries: FIFO, LRU, or LFU.
EnableLruTrackingbooltrueReported only. Timestamp tracking follows EvictionStrategy; auto-validation overwrites whatever you set here.
EnableLfuTrackingboolfalseReported only. Frequency tracking follows EvictionStrategy; auto-validation overwrites whatever you set here.
AutoValidateConfigurationbooltrueAuto-corrects mismatched settings — e.g. enables EnableLfuTracking when EvictionStrategy = LFU.
Note
Set LeastUsedThreshold on its own. There is no setter logic: the two values are reconciled inside Validate(), which Configure calls, and only in one direction — MostUsedThreshold becomes 100 − LeastUsedThreshold when AutoValidateConfiguration is on (the default), and throws when it is off. The 50–99 range check on MostUsedThreshold runs first, so an out-of-range value still throws even though the correction would have overwritten it.

Defaults in code

There is no CacheOptions.Default. The default options object is new CacheOptions(), equivalent to:

var defaults = new CacheOptions
{
    MaxCacheSize              = 1000,
    LeastUsedThreshold        = 25,
    MostUsedThreshold         = 75,
    EvictionStrategy          = CacheEvictionStrategy.LRU,
    EnableLruTracking         = true,
    EnableLfuTracking         = false,
    AutoValidateConfiguration = true,
};

Strategy ↔ tracking matrix

When AutoValidateConfiguration is on, Validate() overwrites the two tracking flags to match EvictionStrategy. With it off, a flag that does not match the strategy throws instead — including the EnableLruTracking default of true under FIFO or LFU.

EvictionStrategyEnableLruTrackingEnableLfuTracking
FIFOfalsefalse
LRUtruefalse
LFUfalsetrue