Package org.cache2k.core.eviction
Class RandomEviction
- java.lang.Object
-
- org.cache2k.core.eviction.AbstractEviction
-
- org.cache2k.core.eviction.RandomEviction
-
- All Implemented Interfaces:
Eviction
public class RandomEviction extends AbstractEviction
- Author:
- Jens Wilke
-
-
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 RandomEviction(HeapCacheForEviction heapCache, InternalEvictionListener listener, long maxSize, org.cache2k.operation.Weigher weigher, long maxWeight)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckIntegrity(IntegrityState integrityState)protected EntryfindEvictionCandidate()Find a candidate for eviction.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 entry from the eviction data structures, because it was evicted or deleted.booleanupdateWeight(Entry e)Updates the weight on the entry and recalculates the total weight if needed.-
Methods inherited from class org.cache2k.core.eviction.AbstractEviction
changeCapacity, close, drain, evictEventually, evictEventuallyBeforeInsert, evictEventuallyBeforeInsertOnSegment, getMetrics, isWeigherPresent, removeAll, removeFromReplacementListOnEvict, runLocked, start, stop, submitWithoutTriggeringEviction, toString, updateAccumulatedWeightInLock, updateHotMax, updateTotalWeightForRemove
-
-
-
-
Constructor Detail
-
RandomEviction
public RandomEviction(HeapCacheForEviction heapCache, InternalEvictionListener listener, long maxSize, org.cache2k.operation.Weigher weigher, long maxWeight)
-
-
Method Detail
-
updateWeight
public boolean updateWeight(Entry e)
Description copied from interface:EvictionUpdates the weight on the entry and recalculates the total weight if needed.Expected not to hold the entry lock, which means, that this does not run in sync with the actual update. That is okay as long as it runs after every update.
Since we need to lock the eviction structure, this can happen in a separate thread.
- Specified by:
updateWeightin interfaceEviction- Overrides:
updateWeightin classAbstractEviction- Returns:
- hint whether eviction should be run. for a bulk operation we want to do eviction once, so not do it within this method
-
removeFromReplacementList
protected void removeFromReplacementList(Entry e)
Description copied from class:AbstractEvictionRemove entry from the eviction data structures, because it was evicted or deleted.- Specified by:
removeFromReplacementListin 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()
Description copied from class:AbstractEvictionFind a candidate for eviction. The method may return the identical if called many times but not sufficient more candidates are available. In any situation, subsequent calls must iterate all entries.- Specified by:
findEvictionCandidatein classAbstractEviction
-
checkIntegrity
public void checkIntegrity(IntegrityState integrityState)
-
removeAllFromReplacementList
protected long removeAllFromReplacementList()
Description copied from class:AbstractEvictionRemove entries from the replacement list without locking the entry itself.- Specified by:
removeAllFromReplacementListin classAbstractEviction
-
getSize
public long getSize()
- Specified by:
getSizein classAbstractEviction
-
-