Top Description Fields Constructors Methods
net.sf.ehcache.store

public abstract Class AbstractPolicy

extends Object
implements Policy
Class Inheritance
All Implemented Interfaces
net.sf.ehcache.store.Policy
Known Direct Subclasses
net.sf.ehcache.store.FifoPolicy, net.sf.ehcache.store.LfuPolicy, net.sf.ehcache.store.LruPolicy
Imports
net.sf.ehcache.Element, java.util.Random

A base policy class
Author
Greg Luck

Field Summary

Modifier and TypeField and Description
pack-priv static final int
DEFAULT_SAMPLE_SIZE

The sample size to use

pack-priv static final Random
RANDOM

Used to select random numbers

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

the smaller of the map size and the default sample size of 30
calculateSampleSize
(int
the size of the store
populationSize
)

sampleSize how many samples to take

public static int[]

Returns:

a list of random offsets
generateRandomSample
(int
the size to draw from
populationSize
)

Generates a random sample from a population

public Element

Returns:

the least hit
selectedBasedOnPolicy
(Element[]
this should be a random subset of the population
sampledElements
,
Element
we never want to select the element just added. May be null.
justAdded
)

Implements net.sf.ehcache.store.Policy.selectedBasedOnPolicy.

Finds the best eviction candidate based on the sampled elements.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_SAMPLE_SIZEback to summary
pack-priv static final int DEFAULT_SAMPLE_SIZE

The sample size to use

RANDOMback to summary
pack-priv static final Random RANDOM

Used to select random numbers

Constructor Detail

AbstractPolicyback to summary
public AbstractPolicy()

Method Detail

calculateSampleSizeback to summary
public static int calculateSampleSize(int populationSize)

sampleSize how many samples to take

Parameters
populationSize:int

the size of the store

Returns:int

the smaller of the map size and the default sample size of 30

generateRandomSampleback to summary
public static int[] generateRandomSample(int populationSize)

Generates a random sample from a population

Parameters
populationSize:int

the size to draw from

Returns:int[]

a list of random offsets

selectedBasedOnPolicyback to summary
public Element selectedBasedOnPolicy(Element[] sampledElements, Element justAdded)

Implements net.sf.ehcache.store.Policy.selectedBasedOnPolicy.

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.

Parameters
sampledElements:Element[]

this should be a random subset of the population

justAdded:Element

we never want to select the element just added. May be null.

Returns:Element

the least hit