Class LRUCache<K,​V>

  • Type Parameters:
    K - key类型
    V - value类型

    public class LRUCache<K,​V>
    extends java.lang.Object
    LRU缓存
    • Constructor Summary

      Constructors 
      Constructor Description
      LRUCache​(int size)
      新建LRU缓存
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      V get​(K key)
      从缓存中取值,会刷新对应缓存的使用情况
      void set​(K key, V value)
      将值放入缓存中
      • Methods inherited from class java.lang.Object

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

      • LRUCache

        public LRUCache​(int size)
        新建LRU缓存
        Parameters:
        size - 缓存容量
    • Method Detail

      • get

        public V get​(K key)
        从缓存中取值,会刷新对应缓存的使用情况
        Parameters:
        key - 缓存key
        Returns:
        key对应的缓存值, 如果不存在, 则返回null
      • set

        public void set​(K key,
                        V value)
        将值放入缓存中
        Parameters:
        key - 缓存key
        value - 缓存value