implement cache statistics

This commit is contained in:
Sebastian Sdorra
2014-02-19 20:56:14 +01:00
parent 5715851ff1
commit ac88e1f651
6 changed files with 351 additions and 5 deletions

View File

@@ -47,6 +47,7 @@ import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
/**
*
@@ -111,6 +112,10 @@ public class GuavaCache<K, V>
{
this.copyStrategy = copyStrategy;
}
else
{
this.copyStrategy = CopyStrategy.NONE;
}
}
//~--- methods --------------------------------------------------------------
@@ -266,19 +271,42 @@ public class GuavaCache<K, V>
if (value != null)
{
value = copyStrategy.copyOnRead(value);
hitCount.incrementAndGet();
}
else
{
missCount.incrementAndGet();
}
return value;
}
/**
* Method description
*
*
* @return
*/
@Override
public CacheStatistics getStatistics()
{
return new CacheStatistics(name, hitCount.get(), missCount.get());
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private com.google.common.cache.Cache<K, V> cache;
private final com.google.common.cache.Cache<K, V> cache;
/** Field description */
private CopyStrategy copyStrategy = CopyStrategy.NONE;
private final CopyStrategy copyStrategy;
/** Field description */
private String name;
private final AtomicLong hitCount = new AtomicLong();
/** Field description */
private final AtomicLong missCount = new AtomicLong();
/** Field description */
private final String name;
}