Package noaa.coastwatch.io
Class CacheOptimizer
java.lang.Object
noaa.coastwatch.io.CacheOptimizer
The CacheOptimizer
class is a helper for caches that
monitors cache access and miss rates and optimizes the cache size. The
algorithm tries to maintain the cache miss rate (ie: page fault rate)
within an acceptable window specified by the caller.
- Since:
- 3.8.1
- Author:
- Peter Hollemans
-
Constructor Summary
ConstructorDescriptionCacheOptimizer
(double minMissRate, double maxMissRate, Runnable growTask, Runnable shrinkTask) Creates a new cache optimizer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
access()
Signals that the cache had an access (either hit or miss).void
miss()
Signals that the cache had a miss.static long
timeOperation
(Runnable operation) Times the execution of an operation that uses the cache to nanosecond precision.
-
Constructor Details
-
CacheOptimizer
public CacheOptimizer(double minMissRate, double maxMissRate, Runnable growTask, Runnable shrinkTask) Creates a new cache optimizer.- Parameters:
minMissRate
- the minimum desired cache miss rate in the range [0..1].maxMissRate
- the maximum desired cache miss rate in the range [0..1].growTask
- the runnable to call to grow the cache size.shrinkTask
- the runnable to call to shrink the cache size.
-
-
Method Details
-
timeOperation
Times the execution of an operation that uses the cache to nanosecond precision.- Parameters:
operation
- the operation to time.- Returns:
- the operation time in nanoseconds (ns).
-
access
public void access()Signals that the cache had an access (either hit or miss). -
miss
public void miss()Signals that the cache had a miss.
-