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 -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new entry to the front of the cache.voidInserts a new entry at the middle of the cache.Retrieves the value associated with the specified key.intbooleanisEmpty()Checks if the cache is empty.iterator()voidMoves the middle pointer back by one position.voidMoves the middle pointer forward by one position.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, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
DoubleListLru
public DoubleListLru()
-
-
Method Details
-
addFirst
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
Inserts a new entry at the middle of the cache.- Parameters:
key- the key of the entryvalue- the value of the entry
-
get
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
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
-
descendingIterator
-