Class DoubleListLru<K,V>

java.lang.Object
org.apache.flink.state.forst.fs.cache.DoubleListLru<K,V>
Type Parameters:
K - the type of keys maintained by this cache
V - the type of mapped values
All Implemented Interfaces:
Iterable<org.apache.flink.api.java.tuple.Tuple2<K,V>>
Direct Known Subclasses:
FileBasedCache

public abstract class DoubleListLru<K,V> extends Object implements Iterable<org.apache.flink.api.java.tuple.Tuple2<K,V>>
A double link LRU (Least Recently Used) cache implementation. This cache maintains two linked lists to manage the cache entries. The first list contains the most recently used entries, and the second list contains the less recently used entries. The cache also maintains a middle pointer to efficiently manage the entries. No thread-safe guarantees are provided.
  • Constructor Details

    • DoubleListLru

      public DoubleListLru()
  • Method Details

    • addFirst

      public void addFirst(K key, V value)
      Adds a new entry to the front of the cache.
      Parameters:
      key - the key of the entry
      value - the value of the entry
    • moveMiddleBack

      public void moveMiddleBack()
      Moves the middle pointer back by one position.
    • moveMiddleFront

      public void moveMiddleFront()
      Moves the middle pointer forward by one position.
    • addSecond

      public void addSecond(K key, V value)
      Inserts a new entry at the middle of the cache.
      Parameters:
      key - the key of the entry
      value - the value of the entry
    • get

      public V get(K key, boolean affectOrder)
      Retrieves the value associated with the specified key. Optionally affects the order of the entries in the cache.
      Parameters:
      key - the key of the entry
      affectOrder - true if the order of the entries should be affected, false otherwise
      Returns:
      the value associated with the key, or null if the key is not found
    • remove

      public V remove(K key)
      Removes the entry associated with the specified key from the cache.
      Parameters:
      key - the key of the entry to be removed
      Returns:
      the value of the removed entry, or null if the key is not found
    • size

      public int size()
      Returns the number of entries in the cache.
      Returns:
      the number of entries in the cache
    • getSecondSize

      public int getSecondSize()
    • isEmpty

      public boolean isEmpty()
      Checks if the cache is empty.
      Returns:
      true if the cache is empty, false otherwise
    • iterator

      public Iterator<org.apache.flink.api.java.tuple.Tuple2<K,V>> iterator()
      Specified by:
      iterator in interface Iterable<K>
    • descendingIterator

      public Iterator<org.apache.flink.api.java.tuple.Tuple2<K,V>> descendingIterator()