Table of Contents

EvictingDictionaryExpiration Class

Definition

Namespace
Bodu.Collections.Generic
Assembly
Bodu.Collections.dll
Package
Bodu.Collections 1.0.0
Source
EvictingDictionaryExpiration.cs

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

timeToLive TimeSpan?

The default lifetime applied to entries added without a per-entry override, or null for no default lifetime.

Exceptions

ArgumentOutOfRangeException

timeToLive is 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

timeToLive TimeSpan?

The default lifetime applied to entries added without a per-entry override, or null for no default lifetime.

kind EvictingDictionaryExpirationKind

The measurement mode for entry lifetimes.

Exceptions

ArgumentOutOfRangeException

timeToLive is non-null and less than or equal to Zero, or kind is 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

timeToLive TimeSpan?

The default lifetime applied to entries added without a per-entry override, or null for no default lifetime.

kind EvictingDictionaryExpirationKind

The measurement mode for entry lifetimes.

timeProvider TimeProvider

The time source used for all clock reads. Must not be null.

Exceptions

ArgumentOutOfRangeException

timeToLive is non-null and less than or equal to Zero, or kind is not a defined EvictingDictionaryExpirationKind value.

ArgumentNullException

timeProvider is 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

TimeSpan?

The default time-to-live, or null when entries added without an explicit per-entry time-to-live never expire.

Applies to

ProductVersions
.NET8, 10