Table of Contents

Interface ICache<TKey, TValue>

Namespace
LfrlAnvil.Caching
Assembly
LfrlAnvil.Core.dll

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

TKey

Entry key (identifier) type.

TValue

Entry 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

key TKey

The 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 key does 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

key TKey

Entry's key.

value TValue

Entry's value.

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.

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

key TKey

Key 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

key TKey

Key of an entry to remove.

removed TValue

An 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

key TKey

Key of an entry to restart.

Returns

bool

true when entry has been restarted (provided key exists), otherwise false.

TryAdd(TKey, TValue)

Attempts to add a new entry.

bool TryAdd(TKey key, TValue value)

Parameters

key TKey

Entry's key.

value TValue

Entry's value.

Returns

bool

true when entry has been added (provided key did not exist), otherwise false.

Remarks

When new entry addition causes Count to exceed Capacity, then the Oldest entry will be removed automatically.