org.weborganic.bastille.cache.util
Class SizeEstimator

java.lang.Object
  extended by org.weborganic.bastille.cache.util.SizeEstimator

public final class SizeEstimator
extends Object

A simple class to estimate the size of a cache based on previously calculated sized and the number of elements.


Method Summary
 boolean checkInMemorySample(Ehcache cache)
          Check whether a new "in memory" size sample need to be re-calculated.
 boolean checkOnDiskSample(Ehcache cache)
          Check whether a new "on disk" size sample need to be re-calculated.
 long estimateInMemorySize(String name, int elements)
          Estimate the "in memory" size based on previous samples.
 long estimateOnDiskSize(String name, int elements)
          Estimate the "on disk" size based on previous samples.
 long getInMemorySize(Ehcache cache)
          Returns the "in memory" size from the cache.
 long getOnDiskSize(Ehcache cache)
          Returns the "on disk" size from the cache.
static SizeEstimator singleton()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

singleton

public static SizeEstimator singleton()
Returns:
the single instance.

checkInMemorySample

public boolean checkInMemorySample(Ehcache cache)
Check whether a new "in memory" size sample need to be re-calculated.

Parameters:
cache - The cache.
Returns:
true if a new sample was recalculated; false otherwise.

checkOnDiskSample

public boolean checkOnDiskSample(Ehcache cache)
Check whether a new "on disk" size sample need to be re-calculated.

Parameters:
cache - The cache.
Returns:
true if a new sample was recalculated; false otherwise.

getInMemorySize

public long getInMemorySize(Ehcache cache)
Returns the "in memory" size from the cache.

This method does not indicate whether the size was calculated or estimated from a previous sample.

Parameters:
cache - The cache
Returns:
return the actual value or -1;

getOnDiskSize

public long getOnDiskSize(Ehcache cache)
Returns the "on disk" size from the cache.

This method does not indicate whether the size was calculated or estimated from a previous sample.

Parameters:
cache - The cache
Returns:
return the actual value or -1;

estimateInMemorySize

public long estimateInMemorySize(String name,
                                 int elements)
Estimate the "in memory" size based on previous samples.

Parameters:
name - The name of the cache
elements - The number of elements
Returns:
return the actual value or -1;

estimateOnDiskSize

public long estimateOnDiskSize(String name,
                               int elements)
Estimate the "on disk" size based on previous samples.

Parameters:
name - The name of the cache
elements - The number of elements
Returns:
return the actual value or -1;