Class LRUCache<K,​V>

    • Field Detail

      • maxCacheSize

        protected int maxCacheSize
        max cache size
    • Constructor Detail

      • LRUCache

        public LRUCache()
        Default constructor for an LRU Cache The default capacity is 10000.
      • LRUCache

        public LRUCache​(int maximumCacheSize)
        Constructs a LRUCache with a maximum capacity.
        Parameters:
        maximumCacheSize - maximum cache size
      • LRUCache

        public LRUCache​(int initialCapacity,
                        int maximumCacheSize,
                        float loadFactor,
                        boolean accessOrder)
        Constructs an empty LRUCache instance with the specified initial capacity, maximumCacheSize,load factor and ordering mode.
        Parameters:
        initialCapacity - the initial capacity.
        maximumCacheSize - maximum cache size
        loadFactor - the load factor.
        accessOrder - the ordering mode - true for access-order, false for insertion-order.
        Throws:
        IllegalArgumentException - if the initial capacity is negative or the load factor is non-positive.
    • Method Detail

      • getMaxCacheSize

        public int getMaxCacheSize()
        Gets max cache size.
        Returns:
        Returns the maxCacheSize.
      • setMaxCacheSize

        public void setMaxCacheSize​(int maxCacheSize)
        Sets max cache size.
        Parameters:
        maxCacheSize - The maxCacheSize to set.
      • removeEldestEntry

        protected boolean removeEldestEntry​(Map.Entry<K,​V> eldest)
        Removes eldest entry.
        Overrides:
        removeEldestEntry in class LinkedHashMap<K,​V>
        Parameters:
        eldest - eldest entry
        Returns:
        true if removed, or false
      • onCacheEviction

        protected void onCacheEviction​(Map.Entry<K,​V> eldest)
        Do nothing for now.
        Parameters:
        eldest - eldest