Table of Contents

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

TKey

The type of keys used to request values.

TValue

The type of values returned.

Inheritance
object
TransparentCacheBase<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

key TKey

Property Value

TValue

Methods

Clear()

Removes all entries from the cache.

[CollectionAccess(CollectionAccessType.ModifyExistingContent)]
public void Clear()

Remove(TKey)

Removes the the entry with the specified key from the cache.

[CollectionAccess(CollectionAccessType.ModifyExistingContent)]
public bool Remove(TKey key)

Parameters

key TKey

Returns

bool

true if a matching entry was found and removed; false if 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

key TKey

Returns

TValue