AbstractExpiringCache

com.phasmidsoftware.lascala.cache.AbstractExpiringCache
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.

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

Graph
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

Members list

Value members

Inherited methods

def andThen[A](g: V => A): K => A

Composes two instances of Function1 in a new Function1, with this function applied first.

Composes two instances of Function1 in a new Function1, with this function applied first.

Type parameters

A

the result type of function g

Value parameters

g

a function R => A

Attributes

Returns

a new function f such that f(x) == g(apply(x))

Inherited from:
Function1
def apply(k: K): V

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.

Value parameters

k

the K value we are interested in

Attributes

Returns

the corresponding V value

Inherited from:
AbstractFulfillingCache
def asMap: Map[K, V]

Attributes

Inherited from:
Mappish
def clear(): Unit

Attributes

Inherited from:
Mappish
def compose[A](g: A => K): A => V

Composes two instances of Function1 in a new Function1, with this function applied last.

Composes two instances of Function1 in a new Function1, with this function applied last.

Type parameters

A

the type to which function g can be applied

Value parameters

g

a function A => T1

Attributes

Returns

a new function f such that f(x) == apply(g(x))

Inherited from:
Function1
def contains(k: K): Boolean

Attributes

Inherited from:
Mappish
def evaluate(k: K): M[V]

Evaluate key k as an M[V]

Evaluate key k as an M[V]

Value parameters

k

the key to be evaluated

Attributes

Returns

a V wrapped in an M

Inherited from:
AbstractFulfillingCache
def get(k: K): M[V]

Non-blocking call to get the value v from the cache.

Non-blocking call to get the value v from the cache.

Value parameters

k

the key of the element which we wish to get

Attributes

Returns

the value wrapped as a T

Inherited from:
Fulfilling
def mutableMap: CacheMap[K, V, M]

Attributes

Inherited from:
AbstractFulfillingCache
override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
AbstractFulfillingCache -> Function1 -> Any
Inherited from:
AbstractFulfillingCache
def unwrap(vm: M[V]): V

Method to unwrap a value of type M[V].

Method to unwrap a value of type M[V].

Value parameters

vm

the M[V] value to be unwrapped

Attributes

Returns

the unwrapped V value

Inherited from:
AbstractFulfillingCache

Inherited and Abstract methods

def expire(k: K): Unit

method to remove a key from the cache

method to remove a key from the cache

Value parameters

k

the key to the element which is to be expired.

Attributes

Inherited from:
Expiring
def fulfill(k: K): M[V]

Fulfill the key k as an M[V]

Fulfill the key k as an M[V]

Value parameters

k

the key to be evaluated

Attributes

Returns

a V wrapped in an M

Inherited from:
Fulfilling
def postFulfillment(k: K, v: V): Unit

method to take action whenever a key value is actually fulfilled.

method to take action whenever a key value is actually fulfilled.

Value parameters

k

the key of the element which has been fulfilled

v

the value of the element which has been fulfilled

Attributes

Inherited from:
Fulfilling