ehcache

net.sf.ehcache.store
Class AbstractPolicy

java.lang.Object
  extended by 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
AbstractPolicy()
           
 
Method Summary
static int[] generateRandomSample(int populationSize)
          Generates a random sample from a population
static int[] generateRandomSampleIndices(int arraySize)
          Generates a random set of indices
 Element selectedBasedOnPolicy(Element[] sampledElements, Element justAdded)
          Finds the best eviction candidate based on the sampled elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.ehcache.store.Policy
compare, getName
 

Constructor Detail

AbstractPolicy

public AbstractPolicy()
Method Detail

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:
selectedBasedOnPolicy in interface Policy
Parameters:
sampledElements - this should be a random subset of the population
justAdded - 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

generateRandomSampleIndices

public static int[] generateRandomSampleIndices(int arraySize)
Generates a random set of indices

Parameters:
arraySize - the maximum number
Returns:
a list of indices, zero based

ehcache

true