com.phasmidsoftware.lascala.cache

Created by scalaprof on 7/12/16.

Attributes

Members list

Type members

Classlikes

abstract class AbstractExpiringCache[K, V, M[_]](m: CacheMap[K, V, M], evaluationFunc: K => M[V])(implicit carper: String => Unit) extends AbstractFulfillingCache[K, V, M], Expiring[K]

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 Expiring[K]
class AbstractFulfillingCache[K, V, M]
trait Fulfilling[K, V, M]
trait Mappish[K, V, M]
trait Cache[K, V, M]
trait K => V
class Object
trait Matchable
class Any
Show all
Known subtypes
abstract class AbstractFulfillingCache[K, V, M[_]](m: CacheMap[K, V, M], evaluationFunc: K => M[V])(implicit carper: String => Unit) extends Cache[K, V, M], Mappish[K, V, M], Fulfilling[K, V, M]

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 Fulfilling[K, V, M]
trait Mappish[K, V, M]
trait Cache[K, V, M]
trait K => V
class Object
trait Matchable
class Any
Show all
Known subtypes
case class BasicFulfillingCache[K, V](evaluationFunc: K => Option[V])(implicit carper: String => Unit) extends OptionFulfillingExpiringCache[K, V]

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 Serializable
trait Product
trait Equals
class AbstractExpiringCache[K, V, Option]
trait Expiring[K]
class AbstractFulfillingCache[K, V, Option]
trait Fulfilling[K, V, Option]
trait Mappish[K, V, Option]
trait Cache[K, V, Option]
trait K => V
class Object
trait Matchable
class Any
Show all
trait Cache[K, V, M[_]] extends K => V

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 => V
class Object
trait Matchable
class Any
Known subtypes
object Cache

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
Cache.type
abstract class CacheMap[K, V, M[_]](val wrapper: Wrapper[M]) extends HashMap[K, V]

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 Serializable
trait 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 Clearable
trait Cloneable[HashMap[K, V]]
trait Cloneable
trait Iterable[(K, V)]
class AbstractMap[K, V]
trait Map[K, V]
trait Pure
trait Equals
trait MapFactoryDefaults[K, V, HashMap, Iterable]
trait MapOps[K, V, HashMap, HashMap[K, V]]
trait PartialFunction[K, V]
trait K => V
class 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 Object
trait Matchable
class Any
Show all
Known subtypes
class FutureHashMap[K, V]
class OptionHashMap[K, V]
class TryHashMap[K, V]
Self type
CacheMap[K, V, M]
trait Expiring[K]

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 Object
trait Matchable
class Any
Known subtypes
trait Fulfilling[K, V, M[_]] extends Mappish[K, V, M]

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
trait Mappish[K, V, M]
class Object
trait Matchable
class Any
Known subtypes
abstract class FutureFulfillingExpiringCache[K, V](evaluationFunc: K => Future[V])(implicit carper: String => Unit, executor: ExecutionContext) extends AbstractExpiringCache[K, V, Future]

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
class AbstractExpiringCache[K, V, Future]
trait Expiring[K]
class AbstractFulfillingCache[K, V, Future]
trait Fulfilling[K, V, Future]
trait Mappish[K, V, Future]
trait Cache[K, V, Future]
trait K => V
class Object
trait Matchable
class Any
Show all
class FutureHashMap[K, V]() extends CacheMap[K, V, Future]

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 CacheMap[K, V, Future]
class HashMap[K, V]
trait Serializable
trait 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 Clearable
trait Cloneable[HashMap[K, V]]
trait Cloneable
trait Iterable[(K, V)]
class AbstractMap[K, V]
trait Map[K, V]
trait Pure
trait Equals
trait MapFactoryDefaults[K, V, HashMap, Iterable]
trait MapOps[K, V, HashMap, HashMap[K, V]]
trait PartialFunction[K, V]
trait K => V
class 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 Object
trait Matchable
class Any
Show all
class FutureWrapper(implicit ec: ExecutionContext, atMost: Duration) extends Wrapper[Future]

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 Wrapper[Future]
class Object
trait Matchable
class Any
trait Mappish[K, V, M[_]]

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 Object
trait Matchable
class Any
Known subtypes
class AbstractFulfillingCache[K, V, M]
class AbstractExpiringCache[K, V, M]
class BasicFulfillingCache[K, V]
class NonExpiringCache[K, V]
trait Fulfilling[K, V, M]
Show all
case class NonExpiringCache[K, V](evaluate: K => Try[V])(implicit carper: String => Unit) extends TryFulfillingExpiringCache[K, V]

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 Serializable
trait Product
trait Equals
class AbstractExpiringCache[K, V, Try]
trait Expiring[K]
class AbstractFulfillingCache[K, V, Try]
trait Fulfilling[K, V, Try]
trait Mappish[K, V, Try]
trait Cache[K, V, Try]
trait K => V
class Object
trait Matchable
class Any
Show all
abstract class OptionFulfillingExpiringCache[K, V](evaluationFunc: K => Option[V])(implicit carper: String => Unit) extends AbstractExpiringCache[K, V, Option]

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
class AbstractExpiringCache[K, V, Option]
trait Expiring[K]
class AbstractFulfillingCache[K, V, Option]
trait Fulfilling[K, V, Option]
trait Mappish[K, V, Option]
trait Cache[K, V, Option]
trait K => V
class Object
trait Matchable
class Any
Show all
Known subtypes
class BasicFulfillingCache[K, V]
class OptionHashMap[K, V]() extends CacheMap[K, V, Option]

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 CacheMap[K, V, Option]
class HashMap[K, V]
trait Serializable
trait 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 Clearable
trait Cloneable[HashMap[K, V]]
trait Cloneable
trait Iterable[(K, V)]
class AbstractMap[K, V]
trait Map[K, V]
trait Pure
trait Equals
trait MapFactoryDefaults[K, V, HashMap, Iterable]
trait MapOps[K, V, HashMap, HashMap[K, V]]
trait PartialFunction[K, V]
trait K => V
class 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 Object
trait Matchable
class Any
Show all
abstract class TryFulfillingExpiringCache[K, V](evaluationFunc: K => Try[V])(implicit carper: String => Unit) extends AbstractExpiringCache[K, V, Try]

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
class AbstractExpiringCache[K, V, Try]
trait Expiring[K]
class AbstractFulfillingCache[K, V, Try]
trait Fulfilling[K, V, Try]
trait Mappish[K, V, Try]
trait Cache[K, V, Try]
trait K => V
class Object
trait Matchable
class Any
Show all
Known subtypes
class NonExpiringCache[K, V]
class TryHashMap[K, V]() extends CacheMap[K, V, Try]

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 CacheMap[K, V, Try]
class HashMap[K, V]
trait Serializable
trait 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 Clearable
trait Cloneable[HashMap[K, V]]
trait Cloneable
trait Iterable[(K, V)]
class AbstractMap[K, V]
trait Map[K, V]
trait Pure
trait Equals
trait MapFactoryDefaults[K, V, HashMap, Iterable]
trait MapOps[K, V, HashMap, HashMap[K, V]]
trait PartialFunction[K, V]
trait K => V
class 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 Object
trait Matchable
class Any
Show all
object Wrapper

Companion object to Wrapper

Companion object to Wrapper

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
Wrapper.type
trait Wrapper[M[_]]

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 Object
trait Matchable
class Any
Known subtypes

Types

type FutureCache[K, V] = Cache[K, V, Future]
type OptionCache[K, V] = Cache[K, V, Option]
type TryCache[K, V] = Cache[K, V, Try]