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 Object
implements Policy

A base policy class

Author:
Greg Luck

Constructor Summary
AbstractPolicy()
           
 
Method Summary
static int calculateSampleSize(int populationSize)
          sampleSize how many samples to take
static int[] generateRandomSample(int populationSize)
          Generates a random sample from a population
 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

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:
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

ehcache

Copyright 2001-2017, Terracotta, Inc.