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 cacheV- 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 Summary
Constructors Constructor Description DoubleListLru()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFirst(K key, V value)Adds a new entry to the front of the cache.voidaddSecond(K key, V value)Inserts a new entry at the middle of the cache.Iterator<org.apache.flink.api.java.tuple.Tuple2<K,V>>descendingIterator()Vget(K key, boolean affectOrder)Retrieves the value associated with the specified key.intgetSecondSize()booleanisEmpty()Checks if the cache is empty.Iterator<org.apache.flink.api.java.tuple.Tuple2<K,V>>iterator()voidmoveMiddleBack()Moves the middle pointer back by one position.voidmoveMiddleFront()Moves the middle pointer forward by one position.Vremove(K key)Removes the entry associated with the specified key from the cache.intsize()Returns the number of entries in the cache.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
addFirst
public void addFirst(K key, V value)
Adds a new entry to the front of the cache.- Parameters:
key- the key of the entryvalue- 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 entryvalue- 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 entryaffectOrder- 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
-
-