Class 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 (&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

      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 the timeToLive.
      B get​(A a)
      Get value from cache or null if it doesn't exist.
      B getOrAdd​(A a)
      Get value from cache or create new value with the getOrAddFactory that was given in the constructor.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • SmallCache

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

      • 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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object