@@ -0,0 +1,998 @@
+package voldemort.utils;%0A%0A%0Aimport voldemort.annotations.concurrency.Threadsafe;%0A%0Aimport java.util.concurrent.Callable;%0Aimport java.util.concurrent.atomic.AtomicReference;%0A%0A@Threadsafe%0Apublic class CachedCallable%3CT%3E implements Callable%3CT%3E %7B%0A%0A    private final Callable%3CT%3E inner;%0A    private final long ttlMs;%0A    private final AtomicReference%3CT%3E valueRef;%0A%0A    private volatile long lastCalledMs;%0A%0A    public CachedCallable(Callable%3CT%3E inner,%0A                          long ttlMs) %7B%0A        this.inner = inner;%0A        this.ttlMs = ttlMs;%0A        valueRef = new AtomicReference%3CT%3E();%0A    %7D%0A%0A%0A    public T call() throws Exception %7B%0A        T value = valueRef.get();%0A        long now = System.currentTimeMillis();%0A        if(value == null %7C%7C now - lastCalledMs %3E ttlMs) %7B%0A            T newValue = inner.call();%0A            if(valueRef.compareAndSet(value, newValue)) %7B%0A                lastCalledMs = now;%0A                return newValue;%0A            %7D%0A        %7D%0A        return valueRef.get();%0A    %7D%0A%7D%0A

Create a cached callable for caching expensive stats