java - LinkedHashMap LRU Cache - Determine what values are removed? -
background information
you can make lru cache linkedhashmap shown at link. basically, just:
- extend linked hash map.
- provide capacity parameter.
- initialize super class (linkedhashmap) parameters tell capacity, scaling factor (which should never used), , keep items in insertion/reference order.
- override removeeldestentry remove oldest entry when capacity breached.
my question
this pretty standard lru cache implementation. 1 thing can't figure out how how notified when linkedhashmap removes entry due not being used enough.
i know can make removeeldestentry provide form of notification... there way retrieve element removed cache right when new 1 inserted (put) underlying map? alternatively, there way query last item removed cache?
is there way retrieve element removed cache right when new 1 inserted (put) underlying map?
the removeeldestentry
notified of entry removed. can add listener method calls if want make dynamically configurable.
from javadoc
protected boolean removeeldestentry(map.entry eldest)
eldest - least inserted entry in map, or if access-ordered map, least accessed entry. entry removed method returns true. if map empty prior put or putall invocation resulting in invocation, entry inserted; in other words, if map contains single entry, eldest entry newest.
.
is there way query last item removed cache?
the last item removed has been removed, have sub-class store entry in field can retrieve later.
Comments
Post a Comment