Package akka.cluster.ddata.protobuf
Class ReplicatorMessageSerializer.SmallCache<A,B>
- java.lang.Object
-
- akka.cluster.ddata.protobuf.ReplicatorMessageSerializer.SmallCache<A,B>
-
- Enclosing class:
- ReplicatorMessageSerializer
public static final class ReplicatorMessageSerializer.SmallCache<A,B> extends java.lang.Object
A cache that is designed for a small number (<= 32) of entries. It is using instance equality. Adding new entry overwrites oldest. It is thread safe but duplicates of same entry may occur.evict
must be called from the outside, i.e. the cache will not cleanup itself.
-
-
Constructor Summary
Constructors Constructor Description SmallCache(int size, scala.concurrent.duration.FiniteDuration timeToLive, scala.Function1<A,B> getOrAddFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(A a, B b)
Add entry to the cache.void
add(scala.Tuple2<A,B> x)
void
evict()
Remove all elements if the cache has not been used within thetimeToLive
.B
get(A a)
Get value from cache ornull
if it doesn't exist.B
getOrAdd(A a)
Get value from cache or create new value with thegetOrAddFactory
that was given in the constructor.java.lang.String
toString()
-
-
-
Method Detail
-
evict
public void evict()
Remove all elements if the cache has not been used within thetimeToLive
.
-
getOrAdd
public B getOrAdd(A a)
Get value from cache or create new value with thegetOrAddFactory
that was given in the constructor. The new value is added to the cache. Duplicates of same value may be added if multiple threads call this concurrently, but decent (low cost) effort is made to reduce the chance of duplicates.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-