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
    System.Object
    Cache<TKey, TValue>
    WeakCache<TKey, TValue>
    Inherited Members
    Cache<TKey, TValue>.Insert(TKey, TValue)
    Cache<TKey, TValue>.TryGet(TKey, TValue)
    Cache<TKey, TValue>.Get(TKey, Func<TKey, TValue>)
    Cache<TKey, TValue>.ContainsKey(TKey)
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    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

    | Improve this Doc View Source

    WeakCache()

    Creates a weak cache.

    Declaration
    public WeakCache()
    | Improve this Doc 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
    System.Collections.Generic.IEqualityComparer<TKey> keyComparer

    A key comparer.

    | Improve this Doc View Source

    WeakCache(IEqualityComparer<TKey>, Int32)

    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
    System.Collections.Generic.IEqualityComparer<TKey> keyComparer

    A key comparer.

    System.Int32 maxConcurrency

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

    Methods

    | Improve this Doc View Source

    Cleanup()

    Explictly cleans up all outdated keys in the weak cache.

    Declaration
    public void Cleanup()
    | Improve this Doc View Source

    Get(TKey, Func<TKey, TValue>)

    Declaration
    public override TValue Get(TKey key, Func<TKey, TValue> createValue)
    Parameters
    Type Name Description
    TKey key
    System.Func<TKey, TValue> createValue
    Returns
    Type Description
    TValue
    Overrides
    Flame.Collections.Cache<TKey, TValue>.Get(TKey, System.Func<TKey, TValue>)
    | Improve this Doc View Source

    Insert(TKey, TValue)

    Declaration
    public override sealed void Insert(TKey key, TValue value)
    Parameters
    Type Name Description
    TKey key
    TValue value
    Overrides
    Flame.Collections.Cache<TKey, TValue>.Insert(TKey, TValue)
    | Improve this Doc View Source

    TryGet(TKey, out TValue)

    Declaration
    public override sealed bool TryGet(TKey key, out TValue value)
    Parameters
    Type Name Description
    TKey key
    TValue value
    Returns
    Type Description
    System.Boolean
    Overrides
    Flame.Collections.Cache<TKey, TValue>.TryGet(TKey, TValue)
    • Improve this Doc
    • View Source
    Back to top Generated by DocFX