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
    System.Object
    SingleCreationValueCache<TKey, TValue>
    Inherited Members
    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: IPA.Utilities.Async
    Assembly: IPA.Loader.dll
    Syntax
    public class SingleCreationValueCache<TKey, TValue>
    Type Parameters
    Name Description
    TKey

    the key type of the cache

    TValue

    the value type of the cache

    Remarks

    This object basically wraps a System.Collections.Concurrent.ConcurrentDictionary`2 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 System.Collections.Generic.IEnumerable<T>, 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
    System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> collection

    the System.Collections.Generic.IEnumerable<T> whose element are to be used for the new cache

    Exceptions
    Type Condition
    System.ArgumentNullException

    when any arguments are null

    System.ArgumentException

    collection contains duplicate keys

    | 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 System.Collections.Generic.IEnumerable<T> has the default concurrency level, has the default initial capacity, and uses the specified System.Collections.Generic.IEqualityComparer<T>.

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

    the System.Collections.Generic.IEnumerable<T> whose elements are to be used for the new cache

    System.Collections.Generic.IEqualityComparer<TKey> comparer

    the equality comparer to use when comparing keys

    Exceptions
    Type Condition
    System.ArgumentNullException

    collection or comparer is null

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

    Declaration
    public SingleCreationValueCache(IEqualityComparer<TKey> comparer)
    Parameters
    Type Name Description
    System.Collections.Generic.IEqualityComparer<TKey> comparer

    the equality comparer to use when comparing keys

    Exceptions
    Type Condition
    System.ArgumentNullException

    comparer is null

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

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