Class TimestampedMap<TKey, TValue>
- Namespace
- RisingV.Shared.Collections
- Assembly
- RisingV.Shared.dll
A map that associates keys with values, each stamped with a UTC timestamp.
public class TimestampedMap<TKey, TValue> where TKey : notnull
Type Parameters
TKey
TValue
- Inheritance
-
TimestampedMap<TKey, TValue>
- Inherited Members
- Extension Methods
Properties
Count
public int Count { get; }
Property Value
Keys
All current keys.
public IEnumerable<TKey> Keys { get; }
Property Value
- IEnumerable<TKey>
Values
All current values (ignores timestamps).
public IEnumerable<TValue> Values { get; }
Property Value
- IEnumerable<TValue>
Methods
AddOrUpdate(TKey, TValue)
Adds or replaces the value for the given key, stamping it with the current time.
public void AddOrUpdate(TKey key, TValue value)
Parameters
key
TKeyvalue
TValue
Clear()
public void Clear()
GetItemsNewerThan(TimeSpan)
Returns all (key, value) pairs whose timestamp is later than or equal to (now - age).
public IEnumerable<KeyValuePair<TKey, TValue>> GetItemsNewerThan(TimeSpan age)
Parameters
age
TimeSpan
Returns
- IEnumerable<KeyValuePair<TKey, TValue>>
GetItemsOlderThan(TimeSpan)
Returns all (key, value) pairs whose timestamp is earlier than (now - age).
public IEnumerable<KeyValuePair<TKey, TValue>> GetItemsOlderThan(TimeSpan age)
Parameters
age
TimeSpan
Returns
- IEnumerable<KeyValuePair<TKey, TValue>>
GetTimestamp(TKey)
Gets the UTC timestamp for when the key was last set or touched, or null if missing.
public DateTime? GetTimestamp(TKey key)
Parameters
key
TKey
Returns
OrderByAscending()
public List<TValue> OrderByAscending()
Returns
- List<TValue>
OrderByDescending()
public List<TValue> OrderByDescending()
Returns
- List<TValue>
Remove(TKey)
Removes an entry entirely.
public bool Remove(TKey key)
Parameters
key
TKey
Returns
RemoveOlderThan(TimeSpan)
Removes all entries older than the specified age.
public void RemoveOlderThan(TimeSpan age)
Parameters
age
TimeSpan
Touch(TKey)
“Touches” an existing key, resetting its timestamp to now. Throws if the key is not present.
public void Touch(TKey key)
Parameters
key
TKey
TryGetValue(TKey, out TValue)
Attempts to get the current value (ignores timestamp).
public bool TryGetValue(TKey key, out TValue value)
Parameters
key
TKeyvalue
TValue