EvictingDictionaryExpiration Class
Definition
Represents the immutable time-based expiration configuration for an EvictingDictionary<TKey, TValue>.
public sealed class EvictingDictionaryExpiration
- Inheritance
-
EvictingDictionaryExpiration
- Inherited Members
- Extension Methods
Remarks
Supplying an EvictingDictionaryExpiration to an EvictingDictionary<TKey, TValue> constructor enables the time dimension of the cache: entries can carry a time-to-live after which they become invisible to lookups and enumeration, independently of the capacity-triggered EvictingDictionaryPolicy. When no expiration configuration is supplied, the dictionary performs no clock reads and behaves exactly as a capacity-only cache.
TimeToLive is the default lifetime applied to entries added without a per-entry override. When null, entries added through Add(TKey, TValue) or the indexer never expire; only entries added through the time-to-live overloads ( Add(TKey, TValue, TimeSpan) and TryAdd(TKey, TValue, TimeSpan)) carry a lifetime.
Kind selects how lifetimes are measured. Under Absolute an entry expires TimeToLive after it was added or last updated. Under Sliding every successful read access - TryGetValue(TKey, out TValue), the indexer getter, and ContainsKey(TKey) - restarts the countdown; enumeration and Touch(TKey) do not.
TimeProvider drives all clock reads, enabling deterministic testing with a fake time source. It defaults to System.
Constructors
EvictingDictionaryExpiration(TimeSpan?)
Initializes a new instance of the EvictingDictionaryExpiration class with the specified default time-to-live, using absolute expiration and the system clock.
public EvictingDictionaryExpiration(TimeSpan? timeToLive)
Parameters
timeToLiveTimeSpan?The default lifetime applied to entries added without a per-entry override, or null for no default lifetime.
Exceptions
- ArgumentOutOfRangeException
timeToLiveis non-null and less than or equal to Zero.
EvictingDictionaryExpiration(TimeSpan?, EvictingDictionaryExpirationKind)
Initializes a new instance of the EvictingDictionaryExpiration class with the specified default time-to-live and expiration kind, using the system clock.
public EvictingDictionaryExpiration(TimeSpan? timeToLive, EvictingDictionaryExpirationKind kind)
Parameters
timeToLiveTimeSpan?The default lifetime applied to entries added without a per-entry override, or null for no default lifetime.
kindEvictingDictionaryExpirationKindThe measurement mode for entry lifetimes.
Exceptions
- ArgumentOutOfRangeException
timeToLiveis non-null and less than or equal to Zero, orkindis not a defined EvictingDictionaryExpirationKind value.
EvictingDictionaryExpiration(TimeSpan?, EvictingDictionaryExpirationKind, TimeProvider)
Initializes a new instance of the EvictingDictionaryExpiration class with the specified default time-to-live, expiration kind, and time provider.
public EvictingDictionaryExpiration(TimeSpan? timeToLive, EvictingDictionaryExpirationKind kind, TimeProvider timeProvider)
Parameters
timeToLiveTimeSpan?The default lifetime applied to entries added without a per-entry override, or null for no default lifetime.
kindEvictingDictionaryExpirationKindThe measurement mode for entry lifetimes.
timeProviderTimeProviderThe time source used for all clock reads. Must not be null.
Exceptions
- ArgumentOutOfRangeException
timeToLiveis non-null and less than or equal to Zero, orkindis not a defined EvictingDictionaryExpirationKind value.- ArgumentNullException
timeProvideris null.
Properties
Kind
Gets the measurement mode for entry lifetimes.
public EvictingDictionaryExpirationKind Kind { get; }
Property Value
- EvictingDictionaryExpirationKind
Absolute when the countdown starts at add/update time; Sliding when successful read accesses restart it.
TimeProvider
Gets the time source used for all clock reads.
public TimeProvider TimeProvider { get; }
Property Value
- TimeProvider
The configured TimeProvider; never null.
TimeToLive
Gets the default lifetime applied to entries added without a per-entry override.
public TimeSpan? TimeToLive { get; }
Property Value
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |