public class LeastRecentlyUsedCache<K,V>
extends java.lang.Object
LRU cache for whatever. Maps key K to value V.
If too many things are stored, values start falling out in the
order they were inserted. Values that are accessed get their
position in the queue refreshed.
Works by keeping a linked list of nodes, implemented as a private
static inner class, and a map from K to the nodes. Needing to keep
track of the nodes is the reason for not using a
java.util.LinkedList.
Could theoretically include most or all of the Map interface, but
so far only what was actually used has been implemented.
- Author:
- John Bauer