Table of Contents

Namespace VpnHood.Net.Toolkit.Collections

Classes

TimeoutDictionary<TKey, TValue>

A concurrent dictionary whose values expire after Timeout of no use and are disposed by the dictionary when evicted, replaced or drained. Ordinary operations take no dictionary-wide application lock (the gated cleanup sweep is the only locked path). Expiry is checked on access and by the sweeps the operations try, with no timer of its own, against a cached clock of about one second's precision. Ownership contract: a value the dictionary adds (or a factory creates) is owned and disposed by the dictionary. One TryAdd returns false for stays the caller's, as it came; one AddOrUpdate rejects because the dictionary is already disposed stays the caller's. A factory may run more than once under contention and must return a fresh instance each time; losing instances are disposed. A returned value may be disposed by a concurrent eviction right after retrieval, so callers must tolerate IsDisposed values and value Dispose must be idempotent. A value's Dispose should not throw: one that does is logged as an error, and the dictionary goes on with the rest.

TimeoutItem

Provides a base for the values of a TimeoutDictionary<TKey, TValue>: the last-used time and the disposed state.

TimeoutItemUtil

Provides the means to clean a list of timeout items.

TimeoutItem<T>

Provides a TimeoutItem that holds a value.

Interfaces

ITimeoutItem

An item managed by TimeoutDictionary<TKey, TValue>. Members are read and written concurrently without synchronization, and the dictionary may dispose an item that another thread still references, so Dispose must be idempotent and the item must tolerate use after disposal. Dispose must not throw: the dictionary does not catch it, and a throw would end a drain part-way.