Class LRUCache<K,​V>

java.lang.Object
java.util.AbstractMap<K,​V>
java.util.HashMap<K,​V>
java.util.LinkedHashMap<K,​V>
xyz.cofe.collection.LRUCache<K,​V>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<K,​V>

public class LRUCache<K,​V>
extends java.util.LinkedHashMap<K,​V>
Простой LRU кэш
Author:
[email protected]
See Also:
Serialized Form
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.util.AbstractMap

    java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected int cacheSizeMax
    Размер кэша
  • Constructor Summary

    Constructors 
    Constructor Description
    LRUCache()
    Конструктор, по умолчанию указывает размер 1000
    LRUCache​(int cacheSizeMax)
    Конструктор
  • Method Summary

    Modifier and Type Method Description
    int getCacheSizeMax()
    Возвращает максимальное кэшируемое кол-во элементов
    protected boolean removeEldestEntry​(java.util.Map.Entry<K,​V> eldest)  
    void setCacheSizeMax​(int cacheSizeMax)
    Указывает максимальное кол-во элементов в кэше

    Methods inherited from class java.util.LinkedHashMap

    clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values

    Methods inherited from class java.util.HashMap

    clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size

    Methods inherited from class java.util.AbstractMap

    equals, hashCode, toString

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.util.Map

    compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
  • Field Details

    • cacheSizeMax

      protected volatile int cacheSizeMax
      Размер кэша
  • Constructor Details

    • LRUCache

      public LRUCache()
      Конструктор, по умолчанию указывает размер 1000
    • LRUCache

      public LRUCache​(int cacheSizeMax)
      Конструктор
      Parameters:
      cacheSizeMax - размер кэша
  • Method Details

    • getCacheSizeMax

      public int getCacheSizeMax()
      Возвращает максимальное кэшируемое кол-во элементов
      Returns:
      максимальное кол-во эл в кэше
    • setCacheSizeMax

      public void setCacheSizeMax​(int cacheSizeMax)
      Указывает максимальное кол-во элементов в кэше
      Parameters:
      cacheSizeMax - максимальное кол-во элементов
    • removeEldestEntry

      protected boolean removeEldestEntry​(java.util.Map.Entry<K,​V> eldest)
      Overrides:
      removeEldestEntry in class java.util.LinkedHashMap<K,​V>