This class implements a cache with a given capacity. Instances are immutable and allow fast access to the keys they contain. When elements are added (either new elements or ones that already exist in the cache) they are put in the front of the cache; if the cache's capacity is reached, elements at the end are discarded.
The intended usage scenario is that a number of read operations is performed on an instance. Based on these operations it is determined which new elements are to be added or which ones need to be put in front. The corresponding updates are then triggered leading to a new instance.
Returns an ''Option'' with the value of the given key and a copy of this instance with the key put in front of the LRU list (if it exists). If the key cannot be found, this instance is returned unchanged.
Returns an ''Option'' with the value of the given key and a copy of this instance with the key put in front of the LRU list (if it exists). If the key cannot be found, this instance is returned unchanged.
Value parameters
key
the key in question
Attributes
Returns
a tuple with the value of this key and the cache instance with the updated LRU list
Queries the given key and returns its value if it is found. Otherwise, the given creator function is invoked with the key, and a pair with the key and the return value is added to this cache. In both cases, the key is now in front of the LRU list.
Queries the given key and returns its value if it is found. Otherwise, the given creator function is invoked with the key, and a pair with the key and the return value is added to this cache. In both cases, the key is now in front of the LRU list.
Value parameters
create
the function to create a new value
key
the key in question
Attributes
Returns
a tuple with the value of the key and the cache instance with the updated LRU list
Adds or updates the given elements to the cache. If keys in the list already exist, they are removed and then added with the new value (which causes them to be moved to the front). If necessary, elements at the end of the LRU list are removed.
Adds or updates the given elements to the cache. If keys in the list already exist, they are removed and then added with the new value (which causes them to be moved to the front). If necessary, elements at the end of the LRU list are removed.