Package net.sf.ehcache.store
Class AbstractPolicy
- java.lang.Object
-
- net.sf.ehcache.store.AbstractPolicy
-
- All Implemented Interfaces:
Policy
- Direct Known Subclasses:
FifoPolicy,LfuPolicy,LruPolicy
public abstract class AbstractPolicy extends java.lang.Object implements Policy
A base policy class- Author:
- Greg Luck
-
-
Constructor Summary
Constructors Constructor Description AbstractPolicy()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static intcalculateSampleSize(int populationSize)sampleSize how many samples to takestatic int[]generateRandomSample(int populationSize)Generates a random sample from a populationElementselectedBasedOnPolicy(Element[] sampledElements, Element justAdded)Finds the best eviction candidate based on the sampled elements.
-
-
-
Method Detail
-
calculateSampleSize
public static int calculateSampleSize(int populationSize)
sampleSize how many samples to take- Parameters:
populationSize- the size of the store- Returns:
- the smaller of the map size and the default sample size of 30
-
selectedBasedOnPolicy
public Element selectedBasedOnPolicy(Element[] sampledElements, Element justAdded)
Finds the best eviction candidate based on the sampled elements. What distuingishes this approach from the classic data structures approach, is that an Element contains metadata which can be used for making policy decisions, while generic data structures do not.- Specified by:
selectedBasedOnPolicyin interfacePolicy- Parameters:
sampledElements- this should be a random subset of the populationjustAdded- we never want to select the element just added. May be null.- Returns:
- the least hit
-
generateRandomSample
public static int[] generateRandomSample(int populationSize)
Generates a random sample from a population- Parameters:
populationSize- the size to draw from- Returns:
- a list of random offsets
-
-