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
TKey
Entry key (identifier) type.
TValue
Entry 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
key
TKeyEntry's key.
value
TValueEntry's value.
lifetime
DurationEntry's lifetime.
Returns
- AddOrUpdateResult
Added when new entry has been added (provided
key
did 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
key
TKeyEntry's key.
value
TValueEntry's value.
lifetime
DurationEntry's lifetime.
Returns
- bool
true when entry has been added (provided
key
did not exist), otherwise false.