Class ClockProPlusEviction
- java.lang.Object
-
- org.cache2k.core.eviction.AbstractEviction
-
- org.cache2k.core.eviction.ClockProPlusEviction
-
- All Implemented Interfaces:
Eviction
public class ClockProPlusEviction extends AbstractEviction
Eviction algorithm inspired from CLOCK Pro with 3 clocks.Uses a static allocation for hot and cold space sizes. No online or dynamic optimization is done yet. However, the hit rate for all measured access traces is better then LRU and it is resistant to scans.
From cache2k version 1.2 to version 1.4 the implementation was simplefied and the demotion of hot entries removed. The result achieves similar or better hitrates.
The Clock-Pro algorithm is explained by the authors in CLOCK-Pro: An Effective Improvement of the CLOCK Replacement and Clock-Pro: An Effective Replacement in OS Kernel.
- Author:
- Jens Wilke
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classClockProPlusEviction.Tunable
-
Field Summary
-
Fields inherited from class org.cache2k.core.eviction.AbstractEviction
heapCache, lock, MAXIMAL_CHUNK_SIZE, maxSize, maxWeight, MINIMAL_CHUNK_SIZE, MINIMUM_CAPACITY_FOR_CHUNKING
-
-
Constructor Summary
Constructors Constructor Description ClockProPlusEviction(HeapCacheForEviction heapCache, InternalEvictionListener listener, long maxSize, org.cache2k.operation.Weigher weigher, long maxWeight, boolean noChunking)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckIntegrity(IntegrityState integrityState)protected EntryfindEvictionCandidate()Runs cold hand an in turn hot hand to find eviction candidate.longgetGhostMax()longgetHotMax()longgetSize()protected voidinsertIntoReplacementList(Entry e)Place the entry as a new entry into the eviction data structures.protected longremoveAllFromReplacementList()Remove entries from the replacement list without locking the entry itself.protected voidremoveFromReplacementList(Entry e)Remove, expire or eviction of an entry happens.voidremoveFromReplacementListOnEvict(Entry e)Track the entry on the ghost list and call the usual remove procedure.StringtoString()protected voidupdateHotMax()Updates hot max based on current size.-
Methods inherited from class org.cache2k.core.eviction.AbstractEviction
changeCapacity, close, drain, evictEventually, evictEventuallyBeforeInsert, evictEventuallyBeforeInsertOnSegment, getMetrics, isWeigherPresent, removeAll, runLocked, start, stop, submitWithoutTriggeringEviction, updateAccumulatedWeightInLock, updateTotalWeightForRemove, updateWeight
-
-
-
-
Constructor Detail
-
ClockProPlusEviction
public ClockProPlusEviction(HeapCacheForEviction heapCache, InternalEvictionListener listener, long maxSize, org.cache2k.operation.Weigher weigher, long maxWeight, boolean noChunking)
-
-
Method Detail
-
getHotMax
public long getHotMax()
-
getGhostMax
public long getGhostMax()
-
updateHotMax
protected void updateHotMax()
Updates hot max based on current size. This is called when eviction kicks in so current size is the maximum size this cache should reach regardless whether we use entry capacity or weigher to limit the size.- Overrides:
updateHotMaxin classAbstractEviction
-
removeAllFromReplacementList
protected long removeAllFromReplacementList()
Description copied from class:AbstractEvictionRemove entries from the replacement list without locking the entry itself.- Specified by:
removeAllFromReplacementListin classAbstractEviction
-
removeFromReplacementListOnEvict
public void removeFromReplacementListOnEvict(Entry e)
Track the entry on the ghost list and call the usual remove procedure.- Overrides:
removeFromReplacementListOnEvictin classAbstractEviction
-
removeFromReplacementList
protected void removeFromReplacementList(Entry e)
Remove, expire or eviction of an entry happens. Remove the entry from the replacement list data structure.Why don't generate ghosts here? If the entry is removed because of a programmatic remove or expiry we should not occupy any resources. Removing and expiry may also take place when no eviction is needed at all, which happens when the cache size did not hit the maximum yet. Producing ghosts would add additional overhead, when it is not needed.
- Specified by:
removeFromReplacementListin classAbstractEviction
-
getSize
public long getSize()
- Specified by:
getSizein classAbstractEviction
-
insertIntoReplacementList
protected void insertIntoReplacementList(Entry e)
Description copied from class:AbstractEvictionPlace the entry as a new entry into the eviction data structures.- Specified by:
insertIntoReplacementListin classAbstractEviction
-
findEvictionCandidate
protected Entry findEvictionCandidate()
Runs cold hand an in turn hot hand to find eviction candidate.- Specified by:
findEvictionCandidatein classAbstractEviction
-
checkIntegrity
public void checkIntegrity(IntegrityState integrityState)
-
toString
public String toString()
- Overrides:
toStringin classAbstractEviction
-
-