This class implements a (mutable, obviously) Cache (aka Memoization) of K,V key-value pairs. In particular, Cache is a lookup function of type K=>V. If no value v for key k has been previously established, the evaluationFunc method will be called when get(k) -- and so also when apply(k) -- is invoked. Otherwise, the existing value will be returned. If the result of calling evaluationFunc(k) is: a Some(v) then v will be put into the internal hashmap and returned; a None then no entry will be put into the internal hashmap (and, as a side-effect, the carper will be invoked). In this way, a caller must be prepared to get None as the result of calling get(k) and must be prepared for an exception to be thrown when calling apply(k). The advantage is that we will only ever try to evaluationFunc a key at most once per expiration period.
OptionFulfillingExpiringCache defines two methods which must be implemented by subclasses: expire (to remove an element from the cache) and postFulfillment (designed to allow a callback method to be invoked when a value is added to the cache, i.e. it is fulfilled).
Created by scalaprof on 4/5/16.
Type parameters
K
they key type
V
the value type
Value parameters
carper
a method which processes a String and returns Unit
evaluationFunc
the method which, in the event of a key-value not being found, will result in an (optional) value
Return a V value for the given K value. This method is not normally called by users of a cache as it could result in an exception being thrown. Use get instead.
Return a V value for the given K value. This method is not normally called by users of a cache as it could result in an exception being thrown. Use get instead.