CachedObjectManagerByMaximumNumberOfItems<'TKey, 'TValue> Type

Manages a bunch of cached objects. The cached object are accessed by a key. In this instance more than one object with the same key can be stored, but it is presumed that all objects which are stored under the same key are considered equal. Usage: Try to take out a cached object with CachedObjectManagerByMaximumNumberOfItems.TryTake. If no such object exists, create a new one. After usage of the object, put it back with CachedObjectManagerByMaximumNumberOfItems.Add. If after adding an object more than the allowed number of objects exists, the object which is used the least will be removed from that instance. The methods in this instance are thread safe.

Two collections are neccessary to store the items: The values are stored in a doubly linked list as KeyValuePairs together with their key. The first item in the doubly linked list is the most recently added item. The last item in the doubly linked list is the least used item. To have fast access to the items by key, a dictionary can be accessed by those keys. The values of this dictionary are HashSets of LinkedListNodes, these LinkedListNodes that are members of the doubly linked list, and whose values are associated with the key.

Constructors

Constructor Description

CachedObjectManagerByMaximumNumberOfItems(maximumNumberOfItems)

Full Usage: CachedObjectManagerByMaximumNumberOfItems(maximumNumberOfItems)

Parameters:
    maximumNumberOfItems : int - The maximum number of items allowed to store.

Initializes a new instance of the CachedObjectManagerByMaximumNumberOfItems class.

maximumNumberOfItems : int

The maximum number of items allowed to store.

ArgumentException maxItemsAllowedToStore must be > 0

Instance members

Instance member Description

this.Add

Full Usage: this.Add

Parameters:
    key : 'TKey - The key under which to store the object.
    value : 'TValue - The value to store.

Adds an object under the specified key.

key : 'TKey

The key under which to store the object.

value : 'TValue

The value to store.

this.Clear

Full Usage: this.Clear

Removes all items in the collection. If the values implement IDisposable, the items are disposed.

this.TryTake

Full Usage: this.TryTake

Parameters:
    key : 'TKey - The key of the object.
    value : byref<'TValue> - On success, the object taken from this collection.

Returns: bool True if the object was found; false otherwise.

Try to take a stored object from this collection. If successfull, this function will return any object that was stored under the given key.

key : 'TKey

The key of the object.

value : byref<'TValue>

On success, the object taken from this collection.

Returns: bool

True if the object was found; false otherwise.