com.phasmidsoftware.lascala.cache
Created by scalaprof on 7/12/16.
Attributes
Members list
Type members
Classlikes
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.
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
Attributes
- Supertypes
- Known subtypes
-
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.
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
Attributes
- Supertypes
-
trait K => Vclass Objecttrait Matchableclass AnyShow all
- Known subtypes
-
Show all
Basic self-fulfilling cache that uses Option
Basic self-fulfilling cache that uses Option
Type parameters
- K
-
they key type
- V
-
the value type
Value parameters
- carper
-
the function to carp about a problem, of type String=>Unit
- evaluationFunc
-
the evaluationFunc function of type K=>Option[V] which will get the V value when it is otherwise unknown.
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait Expiring[K]trait K => Vclass Objecttrait Matchableclass AnyShow all
This trait defines a cache (aka memoization) of K,V key-value pairs. It extends Function1[K,V] so that the apply() method takes a K as parameter and results in a V. If you call the apply method on the cache, it may throw an exception if it is unable to fulfill the value for the given key.
This trait defines a cache (aka memoization) of K,V key-value pairs. It extends Function1[K,V] so that the apply() method takes a K as parameter and results in a V. If you call the apply method on the cache, it may throw an exception if it is unable to fulfill the value for the given key.
Type parameters
- K
-
they key type
- M
-
the container type of the result of calling the get method
- V
-
the value type
Attributes
- Companion
- object
- Supertypes
-
trait K => Vclass Objecttrait Matchableclass Any
- Known subtypes
-
Show all
CONSIDER using WeakHashMap instead of HashMap
CONSIDER using WeakHashMap instead of HashMap
Abstract base class CacheMap which is a subclass of mutable.WeakHashMap with the same key, value types but with an additional parametric type: M (the wrapper/container type).
The reason for extending HashMap (rather than using it directly) is that we need to define a variant of getOrElseUpdate.
Type parameters
- K
-
key type
- M
-
a container which is a monad, such as Option, Future, Try.
- V
-
value type
Value parameters
- wrapper
-
(implicit) a wrapper which is used to create an M[V] object
Attributes
- Supertypes
-
class HashMap[K, V]trait Serializabletrait StrictOptimizedMapOps[K, V, HashMap, HashMap[K, V]]trait StrictOptimizedIterableOps[(K, V), Iterable, HashMap[K, V]]class AbstractMap[K, V]trait Map[K, V]trait MapOps[K, V, HashMap, HashMap[K, V]]trait Shrinkable[K]trait Builder[(K, V), HashMap[K, V]]trait Growable[(K, V)]trait Clearabletrait Cloneable[HashMap[K, V]]trait Cloneabletrait Iterable[(K, V)]class AbstractMap[K, V]trait Map[K, V]trait Puretrait Equalstrait MapFactoryDefaults[K, V, HashMap, Iterable]trait MapOps[K, V, HashMap, HashMap[K, V]]trait PartialFunction[K, V]trait K => Vclass AbstractIterable[(K, V)]trait Iterable[(K, V)]trait IterableFactoryDefaults[(K, V), Iterable]trait IterableOps[(K, V), Iterable, HashMap[K, V]]trait IterableOnceOps[(K, V), Iterable, HashMap[K, V]]trait IterableOnce[(K, V)]class Objecttrait Matchableclass AnyShow all
- Known subtypes
- Self type
-
This trait defines the mechanism for expiring a value from the cache, that's to say the removal of the value. It doesn't say anything about scheduling an expiration.
This trait defines the mechanism for expiring a value from the cache, that's to say the removal of the value. It doesn't say anything about scheduling an expiration.
CONSIDER renaming this trait to MutableCache, or some such name.
Type parameters
- K
-
the key for this expiring object
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
Show all
Trait to define the behavior of a (self)-fulfilling cache.
Trait to define the behavior of a (self)-fulfilling cache.
Created by scalaprof on 7/7/16.
Type parameters
- K
-
they key type
- V
-
the value type
Attributes
- Supertypes
- Known subtypes
-
Show all
This class is almost exactly like SelfFulfillingExpiringCache but the get method returns a Future[V] rather than a Option[V]. There is a corresponding change in the definition of the evaluationFunc function (passed in as a parameter).
This class is almost exactly like SelfFulfillingExpiringCache but the get method returns a Future[V] rather than a Option[V]. There is a corresponding change in the definition of the evaluationFunc function (passed in as a parameter).
Created by scalaprof on 4/5/16.
Type parameters
- K
-
they key type
- V
-
the value type
Value parameters
- carper
-
a (implicit) 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
- executor
-
an (implicit) execution context
Attributes
- Supertypes
This class is a concrete subclass of CacheMap and uses Future as the container "M".
This class is a concrete subclass of CacheMap and uses Future as the container "M".
Type parameters
- K
-
they key type
- V
-
the value type
Attributes
- Supertypes
-
class HashMap[K, V]trait Serializabletrait StrictOptimizedMapOps[K, V, HashMap, HashMap[K, V]]trait StrictOptimizedIterableOps[(K, V), Iterable, HashMap[K, V]]class AbstractMap[K, V]trait Map[K, V]trait MapOps[K, V, HashMap, HashMap[K, V]]trait Shrinkable[K]trait Builder[(K, V), HashMap[K, V]]trait Growable[(K, V)]trait Clearabletrait Cloneable[HashMap[K, V]]trait Cloneabletrait Iterable[(K, V)]class AbstractMap[K, V]trait Map[K, V]trait Puretrait Equalstrait MapFactoryDefaults[K, V, HashMap, Iterable]trait MapOps[K, V, HashMap, HashMap[K, V]]trait PartialFunction[K, V]trait K => Vclass AbstractIterable[(K, V)]trait Iterable[(K, V)]trait IterableFactoryDefaults[(K, V), Iterable]trait IterableOps[(K, V), Iterable, HashMap[K, V]]trait IterableOnceOps[(K, V), Iterable, HashMap[K, V]]trait IterableOnce[(K, V)]class Objecttrait Matchableclass AnyShow all
A concrete Wrapper which wraps with a Future
A concrete Wrapper which wraps with a Future
Value parameters
- atMost
-
a (implicit) duration used by the get method
- ec
-
an (implicit) execution context
Attributes
- Supertypes
Trait to define the behavior of a cache as a map Created by scalaprof on 7/6/16.
Trait to define the behavior of a cache as a map Created by scalaprof on 7/6/16.
Type parameters
- K
-
they key type
- V
-
the value type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
Show all
Basic self-fulfilling cache that uses Try
Basic self-fulfilling cache that uses Try
CONSIDER extending a different superclass since we don't want a cache that even has an expire method.
Type parameters
- K
-
they key type
- V
-
the value type
Value parameters
- carper
-
the function to carp about a problem, of type String=>Unit
- evaluate
-
the evaluationFunc function of type K=>Try[V] which will get the V value when it is otherwise unknown.
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait Expiring[K]trait K => Vclass Objecttrait Matchableclass AnyShow all
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.
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
Attributes
- Supertypes
- Known subtypes
-
This class is a concrete subclass of CacheMap and uses Option as the container "M".
This class is a concrete subclass of CacheMap and uses Option as the container "M".
Type parameters
- K
-
they key type
- V
-
the value type
Attributes
- Supertypes
-
class HashMap[K, V]trait Serializabletrait StrictOptimizedMapOps[K, V, HashMap, HashMap[K, V]]trait StrictOptimizedIterableOps[(K, V), Iterable, HashMap[K, V]]class AbstractMap[K, V]trait Map[K, V]trait MapOps[K, V, HashMap, HashMap[K, V]]trait Shrinkable[K]trait Builder[(K, V), HashMap[K, V]]trait Growable[(K, V)]trait Clearabletrait Cloneable[HashMap[K, V]]trait Cloneabletrait Iterable[(K, V)]class AbstractMap[K, V]trait Map[K, V]trait Puretrait Equalstrait MapFactoryDefaults[K, V, HashMap, Iterable]trait MapOps[K, V, HashMap, HashMap[K, V]]trait PartialFunction[K, V]trait K => Vclass AbstractIterable[(K, V)]trait Iterable[(K, V)]trait IterableFactoryDefaults[(K, V), Iterable]trait IterableOps[(K, V), Iterable, HashMap[K, V]]trait IterableOnceOps[(K, V), Iterable, HashMap[K, V]]trait IterableOnce[(K, V)]class Objecttrait Matchableclass AnyShow all
This class is almost exactly like SelfFulfillingExpiringCache but the get method returns a Try[V] rather than a Option[V]. There is a corresponding change in the definition of the evaluationFunc function (passed in as a parameter).
This class is almost exactly like SelfFulfillingExpiringCache but the get method returns a Try[V] rather than a Option[V]. There is a corresponding change in the definition of the evaluationFunc function (passed in as a parameter).
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
Attributes
- Supertypes
- Known subtypes
-
This class is a concrete subclass of CacheMap and uses Try as the container "M".
This class is a concrete subclass of CacheMap and uses Try as the container "M".
Type parameters
- K
-
they key type
- V
-
the value type
Attributes
- Supertypes
-
class HashMap[K, V]trait Serializabletrait StrictOptimizedMapOps[K, V, HashMap, HashMap[K, V]]trait StrictOptimizedIterableOps[(K, V), Iterable, HashMap[K, V]]class AbstractMap[K, V]trait Map[K, V]trait MapOps[K, V, HashMap, HashMap[K, V]]trait Shrinkable[K]trait Builder[(K, V), HashMap[K, V]]trait Growable[(K, V)]trait Clearabletrait Cloneable[HashMap[K, V]]trait Cloneabletrait Iterable[(K, V)]class AbstractMap[K, V]trait Map[K, V]trait Puretrait Equalstrait MapFactoryDefaults[K, V, HashMap, Iterable]trait MapOps[K, V, HashMap, HashMap[K, V]]trait PartialFunction[K, V]trait K => Vclass AbstractIterable[(K, V)]trait Iterable[(K, V)]trait IterableFactoryDefaults[(K, V), Iterable]trait IterableOps[(K, V), Iterable, HashMap[K, V]]trait IterableOnceOps[(K, V), Iterable, HashMap[K, V]]trait IterableOnce[(K, V)]class Objecttrait Matchableclass AnyShow all
This trait defines a Wrapper of values.
This trait defines a Wrapper of values.
Type parameters
- M
-
represents a container (which is a monad) that we wish to wrap our values in. M is also considered a "higher-kinded type."
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class FutureWrapper