Interface ICache<TKey, TValue>
Represents a generic cache of keyed entries.
public interface 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
Properties
this[TKey]
Gets or sets the entry that has the specified key.
TValue this[TKey key] { get; set; }
Parameters
keyTKeyThe key of the entry to get or set.
Property Value
- TValue
Remarks
See AddOrUpdate(TKey, TValue) for more information about the setter's behavior.
Exceptions
- KeyNotFoundException
Entry with the provided
keydoes not exist.
Methods
AddOrUpdate(TKey, TValue)
Adds a new entry or updates an existing one if key already exists.
AddOrUpdateResult AddOrUpdate(TKey key, TValue value)
Parameters
keyTKeyEntry's key.
valueTValueEntry's value.
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.
Clear()
Removes all entries from the collection.
void Clear()
Remove(TKey)
Attempts to remove an entry with the specified key.
bool Remove(TKey key)
Parameters
keyTKeyKey of an entry to remove.
Returns
- bool
true when entry has been removed, otherwise false.
Remove(TKey, out TValue)
Attempts to remove an entry with the specified key and to return a value associated with that key.
bool Remove(TKey key, out TValue removed)
Parameters
keyTKeyKey of an entry to remove.
removedTValueAn out parameter that returns a value associated with the
key, if it exists.
Returns
- bool
true when entry has been removed, otherwise false.
Restart(TKey)
Attempts to restart an entry associated with the specified key by e.g. moving it to the top of the cache.
bool Restart(TKey key)
Parameters
keyTKeyKey of an entry to restart.
Returns
- bool
true when entry has been restarted (provided
keyexists), otherwise false.
TryAdd(TKey, TValue)
Attempts to add a new entry.
bool TryAdd(TKey key, TValue value)
Parameters
keyTKeyEntry's key.
valueTValueEntry's value.
Returns
- bool
true when entry has been added (provided
keydid not exist), otherwise false.