Interface IIndividualLifetimeCache<TKey, TValue>
Represents a generic cache of keyed entries with a limited lifetime, where each entry can have its own individual lifetime.
public interface IIndividualLifetimeCache<TKey, TValue> : ILifetimeCache<TKey, TValue>, IReadOnlyLifetimeCache<TKey, TValue>, ICache<TKey, TValue>, IReadOnlyCache<TKey, TValue>, IReadOnlyDictionary<TKey, TValue>, IReadOnlyCollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable where TKey : notnull
Type Parameters
TKeyEntry key (identifier) type.
TValueEntry value type.
- Inherited Members
- Extension Methods
Remarks
Reading entries resets their lifetime.
Methods
AddOrUpdate(TKey, TValue, Duration)
Adds a new entry or updates an existing one if key already exists.
AddOrUpdateResult AddOrUpdate(TKey key, TValue value, Duration lifetime)
Parameters
keyTKeyEntry's key.
valueTValueEntry's value.
lifetimeDurationEntry's lifetime.
Returns
- AddOrUpdateResult
Added when new entry has been added (provided
keydid not exist), otherwise Updated.
Remarks
When new entry addition causes Count to exceed Capacity, then the Oldest entry will be removed automatically.
TryAdd(TKey, TValue, Duration)
Attempts to add a new entry.
bool TryAdd(TKey key, TValue value, Duration lifetime)
Parameters
keyTKeyEntry's key.
valueTValueEntry's value.
lifetimeDurationEntry's lifetime.
Returns
- bool
true when entry has been added (provided
keydid not exist), otherwise false.