Search Results for

    Show / Hide Table of Contents

    Class SingleCreationValueCache<TKey, TValue>

    A dictionary-like type intended for thread-safe value caches whose values are created only once ever.

    Inheritance
    Object
    SingleCreationValueCache<TKey, TValue>
    Namespace: IPA.Utilities.Async
    Assembly: IPA.Loader.dll
    Syntax
    public class SingleCreationValueCache<TKey, TValue> : object
    Type Parameters
    Name Description
    TKey

    the key type of the cache

    TValue

    the value type of the cache

    Remarks

    This object basically wraps a with some special handling to ensure that values are only created once ever, without having multiple parallel constructions.

    Constructors

    | Improve this Doc View Source

    SingleCreationValueCache()

    Initializes a new instance of the SingleCreationValueCache<TKey, TValue> class that is empty, has the default concurrency level, has the default initial capacity, and uses the default comparer for the key type.

    Declaration
    public SingleCreationValueCache()
    | Improve this Doc View Source

    SingleCreationValueCache(IEnumerable<KeyValuePair<TKey, TValue>>)

    Initializes a new instance of the SingleCreationValueCache<TKey, TValue> class that contains elements copied from the specified , has the default concurrency level, has the default initial capacity, and uses the default comparer for the key type.

    Declaration
    public SingleCreationValueCache(IEnumerable<KeyValuePair<TKey, TValue>> collection)
    Parameters
    Type Name Description
    IEnumerable<KeyValuePair<TKey, TValue>> collection

    the whose element are to be used for the new cache

    | Improve this Doc View Source

    SingleCreationValueCache(IEnumerable<KeyValuePair<TKey, TValue>>, IEqualityComparer<TKey>)

    Initializes a new instance of the SingleCreationValueCache<TKey, TValue> class that contains elements copied from the specified has the default concurrency level, has the default initial capacity, and uses the specified .

    Declaration
    public SingleCreationValueCache(IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey> comparer)
    Parameters
    Type Name Description
    IEnumerable<KeyValuePair<TKey, TValue>> collection

    the whose elements are to be used for the new cache

    IEqualityComparer<TKey> comparer

    the equality comparer to use when comparing keys

    | Improve this Doc View Source

    SingleCreationValueCache(IEqualityComparer<TKey>)

    Initializes a new instance of the SingleCreationValueCache<TKey, TValue> class that is empty, has the default concurrency level and capacity, and uses the specified .

    Declaration
    public SingleCreationValueCache(IEqualityComparer<TKey> comparer)
    Parameters
    Type Name Description
    IEqualityComparer<TKey> comparer

    the equality comparer to use when comparing keys

    Properties

    | Improve this Doc View Source

    Count

    Gets the number of elements that this cache contains.

    Declaration
    public int Count { get; }
    Property Value
    Type Description
    Int32
    | Improve this Doc View Source

    IsEmpty

    Gets a value that indicates whether this cache is empty.

    Declaration
    public bool IsEmpty { get; }
    Property Value
    Type Description
    Boolean

    Methods

    | Improve this Doc View Source

    Clear()

    Clears the cache.

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

    ContainsKey(TKey)

    Gets a value indicating whether or not this cache contains key.

    Declaration
    public bool ContainsKey(TKey key)
    Parameters
    Type Name Description
    TKey key

    the key to search for

    Returns
    Type Description
    Boolean

    true if the cache contains the key, false otherwise

    | Improve this Doc View Source

    GetOrAdd(TKey, Func<TKey, TValue>)

    Gets the value associated with the specified key from the cache. If it does not exist, and no creators are currently running for this key, then the creator is called to create the value and the value is added to the cache. If there is a creator currently running for the key, then this waits for the creator to finish and retrieves the value.

    Declaration
    public TValue GetOrAdd(TKey key, Func<TKey, TValue> creator)
    Parameters
    Type Name Description
    TKey key

    the key to search for

    Func<TKey, TValue> creator

    the delegate to use to create the value if it does not exist

    Returns
    Type Description
    TValue

    the value that was found, or the result of creator

    | Improve this Doc View Source

    ToArray()

    Copies the key-value pairs stored by the cache to a new array, filtering all elements that are currently being created.

    Declaration
    public KeyValuePair<TKey, TValue>[] ToArray()
    Returns
    Type Description
    KeyValuePair<TKey, TValue>[]

    an array containing a snapshot of the key-value pairs contained in this cache

    | Improve this Doc View Source

    TryGetValue(TKey, out TValue)

    Attempts to get the value associated with the specified key from the cache.

    Declaration
    public bool TryGetValue(TKey key, out TValue value)
    Parameters
    Type Name Description
    TKey key

    the key to search for

    TValue value

    the value retrieved, if any

    Returns
    Type Description
    Boolean

    true if the value was found, false otherwise

    Extension Methods

    ReflectionUtil.SetField<T, U>(T, String, U)
    ReflectionUtil.GetField<U, T>(T, String)
    ReflectionUtil.SetProperty<T, U>(T, String, U)
    ReflectionUtil.GetProperty<U, T>(T, String)
    ReflectionUtil.InvokeMethod<U, T>(T, String, Object[])
    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX