コード例 #1
0
  @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;
              }
            });
  }
コード例 #2
0
 @Override
 public boolean isInitialized() {
   return cache.get(cacheKey) != null;
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 @Override
 public void clear() {
   cache.remove(cacheKey);
 }