Tip
You can retrieve a thread-safe accessor by the GetThreadSafeAccessor method.
public TValue this[
TKey key
] { get; set; }
Public Default Property Item (
key As TKey
) As TValue
Get
Set
public:
virtual property TValue default[TKey key] {
TValue get (TKey key) sealed;
void set (TKey key, TValue value) sealed;
}
abstract Item : 'TValue with get, set
override Item : 'TValue with get, set
Getting this property retrieves the needed element, while setting adds a new item (or overwrites an already existing item). If this CacheTKey, TValue instance was initialized by a non- item loader, then it is enough to use only the get accessor because that will load elements into the cache by the delegate instance that was passed to the constructor. When the cache was initialized without an item loader, then getting a non-existing key will throw a KeyNotFoundException.
If an item loader was passed to the constructor, then it is transparent whether the returned value of this property was in the cache before retrieving it. To test whether a key exists in the cache, use the ContainsKey method. To retrieve a key only when it already exists in the cache, use the TryGetValue method.
When the CacheTKey, TValue is full (that is, when Count equals to Capacity) and a new item is added, an element (depending on Behavior property) will be dropped from the cache.
If EnsureCapacity is , getting or setting this property approaches an O(1) operation. Otherwise, when the capacity of the inner storage must be increased to accommodate a new element, this property becomes an O(n) operation, where n is Count.
ArgumentNullException | key is null. |
KeyNotFoundException | The property is retrieved, the CacheTKey, TValue has been initialized without an item loader and key does not exist in the cache. |