Class TransparentCacheBase<TKey, TValue>
- Namespace
- NanoByte.Common.Collections
- Assembly
- NanoByte.Common.dll
Transparently caches retrieval requests, passed through to a template method on first request.
public abstract class TransparentCacheBase<TKey, TValue> where TKey : notnull
Type Parameters
TKeyThe type of keys used to request values.
TValueThe type of values returned.
- Inheritance
-
objectTransparentCacheBase<TKey, TValue>
- Derived
- Extension Methods
Remarks
This class is thread-safe.
Properties
this[TKey]
Retrieves a value from the cache.
[CollectionAccess(CollectionAccessType.Read)]
public TValue this[TKey key] { get; }
Parameters
keyTKey
Property Value
- TValue
Methods
Clear()
Removes all entries from the cache.
[CollectionAccess(CollectionAccessType.ModifyExistingContent)]
public void Clear()
Remove(TKey)
Removes the entry with the specified key from the cache.
[CollectionAccess(CollectionAccessType.ModifyExistingContent)]
public bool Remove(TKey key)
Parameters
keyTKey
Returns
- bool
trueif a matching entry was found and removed;falseif no matching entry was in the cache.
Retrieve(TKey)
Template method used to retrieve values not yet in the cache. Usually only called once per key. May be called multiple times in multi-threaded scenarios.
protected abstract TValue Retrieve(TKey key)
Parameters
keyTKey
Returns
- TValue