Search Results for

    Show / Hide Table of Contents

    Class LruCache<TKey, TValue>

    A cache implementation that uses the least recently used (LRU) policy to evict stale key-value pairs.

    Inheritance
    object
    Cache<TKey, TValue>
    LruCache<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 LruCache<TKey, TValue> : Cache<TKey, TValue>
    Type Parameters
    Name Description
    TKey
    TValue

    Constructors

    | Edit this page View Source

    LruCache(int)

    Creates an LRU cache with a particular capacity.

    Declaration
    public LruCache(int capacity)
    Parameters
    Type Name Description
    int capacity

    The maximal number of key-value pairs in the LRU cache.

    | Edit this page View Source

    LruCache(int, IEqualityComparer<TKey>)

    Creates an LRU cache with a particular capacity and a key equality comparer.

    Declaration
    public LruCache(int capacity, IEqualityComparer<TKey> comparer)
    Parameters
    Type Name Description
    int capacity

    The maximal number of key-value pairs in the LRU cache.

    IEqualityComparer<TKey> comparer

    An equality comparer for keys.

    Properties

    | Edit this page View Source

    Capacity

    Gets the LRU cache's capacity.

    Declaration
    public int Capacity { get; }
    Property Value
    Type Description
    int

    The maximal number of key-value pairs in the LRU cache.

    Methods

    | 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 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 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