EvictingDictionaryPolicy Enum
Definition
Specifies the eviction strategy used by an EvictingDictionary<TKey, TValue> when its capacity is exceeded.
public enum EvictingDictionaryPolicy
- Extension Methods
Fields
FirstInFirstOut = 0First-In, First-Out (FIFO): evicts the item that was added earliest, regardless of usage.
LeastRecentlyUsed = 1Least Recently Used (LRU): evicts the item that has not been accessed for the longest time.
LeastFrequentlyUsed = 2Least Frequently Used (LFU): evicts the item with the fewest total accesses.
MostRecentlyUsed = 3Most Recently Used (MRU): evicts the most recently accessed item.
RandomReplacement = 4Random Replacement: evicts a randomly selected item.
SecondChance = 5Second Chance: evicts the first item found without a recent access flag, allowing items a second chance before removal.
Remarks
The EvictingDictionaryPolicy enumeration defines how items are selected for removal when the dictionary reaches its maximum capacity. The selected policy determines whether the dictionary behaves like a queue, cache, or frequency-based store.
Eviction Example:
Consider a dictionary with a capacity of 3. The following operations occur
in order:
Add("A") // Dictionary: A
Add("B") // Dictionary: A, B
Add("C") // Dictionary: A, B, C
Access("A") // Marks "A" as recently used or increases its frequency
Add("D") // Triggers eviction: Dictionary must remove one entry
The item that is evicted varies depending on the selected EvictingDictionaryPolicy:
| Policy | Item Evicted |
|---|---|
| FirstInFirstOut | "A" - the first item added, regardless of access. |
| LeastRecentlyUsed | "C" - the item least recently accessed (A was accessed, C was not). |
| LeastFrequentlyUsed | "B" - the first item with the lowest access count. |
| MostRecentlyUsed | "A" - the most recently accessed item. |
| RandomReplacement | A randomly chosen item from "A", "B", or "C". |
| SecondChance |
"B" - evicted after its reference bit is cleared; "A" is spared due to recent access.
|
This example highlights the behavioral differences across policies using the same input sequence. Actual eviction order may vary depending on access patterns, dictionary configuration, and implementation details.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |