@Override @SuppressWarnings("hiding") public T get(final Supplier<T> supplier) { return (T) cache.get( cacheKey, new EvictionAwareCacheLoader<Integer, Object, RuntimeException>() { @Override public Object load(Integer key) throws RuntimeException { return supplier.get(); } @Override public int size() throws RuntimeException { return elementSize; } @Override public EvictionListener evictionListener() { return supplier instanceof EvictionSupplier ? ((EvictionSupplier) supplier).evictionListener() : null; } }); }
@Override public boolean isInitialized() { return cache.get(cacheKey) != null; }
/** * This ctor allows to preset the value. This can be used if the value is available when * initialized but may be reclaimed during processing. * * @param elementSize The size of the value in the cache in bytes. * @param supplier */ public CachedLazyInit(T value, int elementSize, Supplier<T> supplier) { super(supplier); cache.putIfAbsent(cacheKey, value, elementSize); this.elementSize = elementSize; }
@Override public void clear() { cache.remove(cacheKey); }