Top Description Methods
net.sf.ehcache.store

public Interface Policy

Known Direct Implementers
net.sf.ehcache.store.AbstractPolicy
Imports
net.sf.ehcache.Element

An eviction policy.

The Cache will use a policy at startup. There are three policy implementations provided in ehcache: LRU, LFU and FIFO. However many other policies are possible. That the policy has access to the whole element enables policies based on the key, value, metadata, statistics, or a combination of any of the above.

Author
Greg Luck

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the second element is preferable for eviction to the first element under ths policy
compare
(Element
the element to compare against
element1
,
Element
the element to compare
element2
)

Compares the desirableness for eviction of two elements

public String

Returns:

the name of the Policy. Inbuilt examples are LRU, LFU and FIFO.
getName
()

public Element

Returns:

the selected Element
selectedBasedOnPolicy
(Element[]
this should be a random subset of the population
sampledElements
,
Element
we probably never want to select the element just added. It is provided so that it can be ignored if selected. May be null.
justAdded
)

Finds the best eviction candidate based on the sampled elements.

Method Detail

compareback to summary
public boolean compare(Element element1, Element element2)

Compares the desirableness for eviction of two elements

Parameters
element1:Element

the element to compare against

element2:Element

the element to compare

Returns:boolean

true if the second element is preferable for eviction to the first element under ths policy

getNameback to summary
public String getName()
Returns:String

the name of the Policy. Inbuilt examples are LRU, LFU and FIFO.

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

Finds the best eviction candidate based on the sampled elements. What distinguishes this approach from the classic data structures approach is that an Element contains metadata (e.g. usage statistics) which can be used for making policy decisions, while generic data structures do not. It is expected that implementations will take advantage of that metadata.

Parameters
sampledElements:Element[]

this should be a random subset of the population

justAdded:Element

we probably never want to select the element just added. It is provided so that it can be ignored if selected. May be null.

Returns:Element

the selected Element