This abstract 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 Success(v) then v will be put into the internal hashmap and returned; a Failure(x) then no entry will be put into the internal hashmap (as a side-effect, the carper will be invoked for a failure) 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.
CONSIDER do we really need the carper method now that we return a Try[V] from apply?
Created by scalaprof on 4/5/16.
Type parameters
K
they key type
M
a container (a monad) such as Try, Option, Future.
V
the value type
Value parameters
carper
a method which processes a String and returns Unit
m
a CacheMap which is where the cached values will actually be stored
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.