Class Cache

  • All Implemented Interfaces:
    TreeCache

    public final class Cache
    extends java.lang.Object
    implements TreeCache
    Concurrent (thread-safe) FIFO tree cache (using classes from java.util.concurrent). After the cache size reached a certain limit, some least recently used entry are removed, when adding a new entry.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int capacity  
      private java.util.concurrent.ConcurrentMap<java.lang.String,​Tree> map  
      private java.util.concurrent.ConcurrentLinkedQueue<java.lang.String> queue  
      private java.util.concurrent.atomic.AtomicInteger size  
    • Constructor Summary

      Constructors 
      Constructor Description
      Cache​(int capacity)
      Creates a new cache with the specified capacity and default concurrency level (16).
      Cache​(int capacity, int concurrencyLevel)
      Creates a new cache with the specified capacity and concurrency level.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Tree get​(java.lang.String expression)
      Lookup tree
      void put​(java.lang.String expression, Tree tree)
      Cache tree
      int size()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • map

        private final java.util.concurrent.ConcurrentMap<java.lang.String,​Tree> map
      • queue

        private final java.util.concurrent.ConcurrentLinkedQueue<java.lang.String> queue
      • size

        private final java.util.concurrent.atomic.AtomicInteger size
      • capacity

        private final int capacity
    • Constructor Detail

      • Cache

        public Cache​(int capacity)
        Creates a new cache with the specified capacity and default concurrency level (16).
        Parameters:
        capacity - Cache size. The actual size may exceed it temporarily.
      • Cache

        public Cache​(int capacity,
                     int concurrencyLevel)
        Creates a new cache with the specified capacity and concurrency level.
        Parameters:
        capacity - Cache size. The actual map size may exceed it temporarily.
        concurrencyLevel - The estimated number of concurrently updating threads. The implementation performs internal sizing to try to accommodate this many threads.
    • Method Detail

      • size

        public int size()
      • get

        public Tree get​(java.lang.String expression)
        Description copied from interface: TreeCache
        Lookup tree
        Specified by:
        get in interface TreeCache
      • put

        public void put​(java.lang.String expression,
                        Tree tree)
        Description copied from interface: TreeCache
        Cache tree
        Specified by:
        put in interface TreeCache