Class ReplicatorMessageSerializer.SmallCache<A,B>

java.lang.Object
org.apache.pekko.cluster.ddata.protobuf.ReplicatorMessageSerializer.SmallCache<A,B>
Enclosing class:
ReplicatorMessageSerializer

public static final class ReplicatorMessageSerializer.SmallCache<A,B> extends Object
A cache that is designed for a small number (&lt;= 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

    Modifier and Type
    Method
    Description
    void
    add(A a, B b)
    Add entry to the cache.
    void
    add(scala.Tuple2<A,B> x)
     
    void
    Remove all elements if the cache has not been used within the timeToLive.
    get(A a)
    Get value from cache or null if it doesn't exist.
    Get value from cache or create new value with the getOrAddFactory that was given in the constructor.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SmallCache

      public SmallCache(int size, scala.concurrent.duration.FiniteDuration timeToLive, scala.Function1<A,B> getOrAddFactory)
  • Method Details

    • add

      public void add(A a, B b)
      Add entry to the cache. Overwrites oldest entry.
    • add

      public void add(scala.Tuple2<A,B> x)
    • evict

      public void evict()
      Remove all elements if the cache has not been used within the timeToLive.
    • get

      public B get(A a)
      Get value from cache or null if it doesn't exist.
    • getOrAdd

      public B getOrAdd(A a)
      Get value from cache or create new value with the getOrAddFactory 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 String toString()
      Overrides:
      toString in class Object