Class Cache

  • All Implemented Interfaces:
    TreeCache

    public final class Cache
    extends java.lang.Object
    implements TreeCache
    Simple (thread-safe) LRU cache. After the cache size reached a certain limit, the least recently used entry is removed, when adding a new entry.
    Author:
    Christoph Beck
    • Constructor Summary

      Constructors 
      Constructor Description
      Cache​(int size)
      Constructor.
      Cache​(int size, java.util.Map<java.lang.String,​Tree> secondary)
      Constructor.
    • 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
      • Methods inherited from class java.lang.Object

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

      • Cache

        public Cache​(int size)
        Constructor. Use a WeakHashMap as secondary map.
        Parameters:
        size - maximum primary cache size
      • Cache

        public Cache​(int size,
                     java.util.Map<java.lang.String,​Tree> secondary)
        Constructor. If the least recently used entry is removed from the primary cache, it is added to the secondary map.
        Parameters:
        size - maximum primary cache size
        secondary - the secondary map (may be null)
    • Method Detail

      • 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