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.
Constructor | Description | ||
Full Usage:
CachedObjectManagerByMaximumNumberOfItems(maximumNumberOfItems)
Parameters:
int
-
The maximum number of items allowed to store.
|
|
Instance member | Description |
Full Usage:
this.Add
Parameters:
'TKey
-
The key under which to store the object.
value : 'TValue
-
The value to store.
|
Adds an object under the specified key.
|
Full Usage:
this.Clear
|
|
Full Usage:
this.TryTake
Parameters:
'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.
|