Class LRUCache

  • All Implemented Interfaces:
    Cache

    public class LRUCache
    extends java.lang.Object
    implements Cache
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int limit  
      private java.util.concurrent.locks.ReentrantLock lock  
      private java.util.Map<java.lang.String,​JsonPath> map  
      private java.util.Deque<java.lang.String> queue  
    • Constructor Summary

      Constructors 
      Constructor Description
      LRUCache​(int limit)  
    • Field Detail

      • lock

        private final java.util.concurrent.locks.ReentrantLock lock
      • map

        private final java.util.Map<java.lang.String,​JsonPath> map
      • queue

        private final java.util.Deque<java.lang.String> queue
      • limit

        private final int limit
    • Constructor Detail

      • LRUCache

        public LRUCache​(int limit)
    • Method Detail

      • put

        public void put​(java.lang.String key,
                        JsonPath value)
        Description copied from interface: Cache
        Add JsonPath to the cache
        Specified by:
        put in interface Cache
        Parameters:
        key - cache key to store the JsonPath
        value - JsonPath to be cached
      • get

        public JsonPath get​(java.lang.String key)
        Description copied from interface: Cache
        Get the Cached JsonPath
        Specified by:
        get in interface Cache
        Parameters:
        key - cache key to lookup the JsonPath
        Returns:
        JsonPath
      • addKey

        private void addKey​(java.lang.String key)
      • removeLast

        private java.lang.String removeLast()
      • removeThenAddKey

        private void removeThenAddKey​(java.lang.String key)
      • removeFirstOccurrence

        private void removeFirstOccurrence​(java.lang.String key)
      • getSilent

        public JsonPath getSilent​(java.lang.String key)
      • remove

        public void remove​(java.lang.String key)
      • size

        public int size()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object