Search Results for

    Show / Hide Table of Contents

    Class WeakCache<TKey, TValue>

    A cache that maps keys to values for as long as neither the key nor the value of a key-value pair is garbage-collected. Weak caches do not prevent keys or values from being garbage-collected.

    Inheritance
    object
    Cache<TKey, TValue>
    WeakCache<TKey, TValue>
    Inherited Members
    Cache<TKey, TValue>.Insert(TKey, TValue)
    Cache<TKey, TValue>.TryGet(TKey, out TValue)
    Cache<TKey, TValue>.Get(TKey, Func<TKey, TValue>)
    Cache<TKey, TValue>.ContainsKey(TKey)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Flame.Collections
    Assembly: Flame.dll
    Syntax
    public sealed class WeakCache<TKey, TValue> : Cache<TKey, TValue> where TKey : class where TValue : class
    Type Parameters
    Name Description
    TKey
    TValue
    Remarks

    Public instance methods of this class are thread-safe.

    Constructors

    | Edit this page View Source

    WeakCache()

    Creates a weak cache.

    Declaration
    public WeakCache()
    | Edit this page View Source

    WeakCache(IEqualityComparer<TKey>)

    Creates a weak cache that uses a particular key comparer under the hood.

    Declaration
    public WeakCache(IEqualityComparer<TKey> keyComparer)
    Parameters
    Type Name Description
    IEqualityComparer<TKey> keyComparer

    A key comparer.

    | Edit this page View Source

    WeakCache(IEqualityComparer<TKey>, int)

    Creates a weak cache that uses a particular key comparer under the hood and can be accessed by up to maxConcurrency threads simultaneously (under ideal circumstances).

    Declaration
    public WeakCache(IEqualityComparer<TKey> keyComparer, int maxConcurrency)
    Parameters
    Type Name Description
    IEqualityComparer<TKey> keyComparer

    A key comparer.

    int maxConcurrency

    The maximum number of threads that can access the weak cache simultaneously under optimal circumstances.

    Methods

    | Edit this page View Source

    Cleanup()

    Explictly cleans up all outdated keys in the weak cache.

    Declaration
    public void Cleanup()
    | Edit this page View Source

    Get(TKey, Func<TKey, TValue>)

    Queries the cache for the value with a particular key. If that value cannot be found, the key is recomputed.

    Declaration
    public override TValue Get(TKey key, Func<TKey, TValue> createValue)
    Parameters
    Type Name Description
    TKey key

    The key of the value to query.

    Func<TKey, TValue> createValue

    A callback that creates the value for the key, in case the key was not in the cache.

    Returns
    Type Description
    TValue

    The value for the key.

    Overrides
    Cache<TKey, TValue>.Get(TKey, Func<TKey, TValue>)
    | Edit this page View Source

    Insert(TKey, TValue)

    Inserts a new key-value pair into this cache, or overwrites the value for an existing key.

    Declaration
    public override sealed void Insert(TKey key, TValue value)
    Parameters
    Type Name Description
    TKey key

    The cached value's key.

    TValue value

    The value to cache.

    Overrides
    Cache<TKey, TValue>.Insert(TKey, TValue)
    | Edit this page View Source

    TryGet(TKey, out TValue)

    Tries to query the cache for the value with a particular key.

    Declaration
    public override sealed bool TryGet(TKey key, out TValue value)
    Parameters
    Type Name Description
    TKey key

    The key of the value to query.

    TValue value

    A cached value, if any.

    Returns
    Type Description
    bool

    true if a value for the given key was found in the cache; otherwise, false.

    Overrides
    Cache<TKey, TValue>.TryGet(TKey, out TValue)
    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX