package org.apache.cassandra.cache;
import java.util.Iterator;
import org.apache.cassandra.metrics.CacheMetrics;
public class InstrumentingCache<K, V>
{
private final ICache<K, V> map;
private final String type;
private CacheMetrics metrics;
public InstrumentingCache(String type, ICache<K, V> map)
{
this.map = map;
this.type = type;
this.metrics = new CacheMetrics(type, map);
}
public void put(K key, V value)
{
map.put(key, value);
}
public boolean putIfAbsent(K key, V value)
{
return map.putIfAbsent(key, value);
}
public boolean replace(K key, V old, V value)
{
return map.replace(key, old, value);
}
public V get(K key)
{
V v = map.get(key);
metrics.requests.mark();
if (v != null)
metrics.hits.mark();
return v;
}
public V getInternal(K key)
{
return map.get(key);
}
public void remove(K key)
{
map.remove(key);
}
public long getCapacity()
{
return map.capacity();
}
public void setCapacity(long capacity)
{
map.setCapacity(capacity);
}
public int size()
{
return map.size();
}
public long weightedSize()
{
return map.weightedSize();
}
public void clear()
{
map.clear();
metrics = new CacheMetrics(type, map);
}
public Iterator<K> keyIterator()
{
return map.keyIterator();
}
public Iterator<K> hotKeyIterator(int n)
{
return map.hotKeyIterator(n);
}
public boolean containsKey(K key)
{
return map.containsKey(key);
}
public CacheMetrics getMetrics()
{
return metrics;
}
}