Code example for Cache

Methods: getIfPresentput

0
            this.id = id;
            this.stats = stats;
        } 
 
        public T load(Factory<T> createIfNotPresent) {
            T out = cache.getIfPresent(id);
            if (out != null) {
                stats.readFromCache();
                return out;
            } 
            long start = System.currentTimeMillis();
            T value = createIfNotPresent.create();
            stats.readFromDisk(start);
            cache.put(id, value);
            return value;
        } 
    } 
}