/** * Use a shared cache. */ public Typed<T> cache(Cache<T> cache) { if (cache == null) { throw new IllegalArgumentException("'cache' must not be null"); } return new Typed<T>(any, cache, loader, typedCacheBuilder); }
/** * Allows an unbounded cache. * <p> * This could leak memory, since the provided cache implementation will never expire * entries. * * @see Any#unbounded(Loader) */ public Typed<T> unbounded(Loader<T> loader) { return cache(new ConcurrentHashMap<T, MetricId>(), loader); }
/** * Configure a specific cache instance, use this if you wish for the consequent builders to * re-use the same cache instance. */ public Typed<T> cache(final ConcurrentMap<T, MetricId> map, Loader<T> loader) { if (map == null) { throw new IllegalArgumentException("'cache' must not be null"); } return loader(loader).typedCacheBuilder(new TypedCacheBuilder<T>() { @Override public Cache<T> build(Loader<T> loader) { return new ConcurrentMapCache<T>(map, loader); } }); }
private Typed<T> typedCacheBuilder(TypedCacheBuilder<T> typedCacheBuilder) { return new Typed<T>(any, cache, loader, typedCacheBuilder); }
public Typed<T> cacheBuilder(CacheBuilder cacheBuilder) { return any(any.cacheBuilder(cacheBuilder)); }
private Typed<T> any(Any any) { return new Typed<>(any, cache, loader, typedCacheBuilder); } }
/** * Configure a base metric id. * * @see Any#metricId(MetricId) */ public Typed<T> metricId(MetricId base) { return any(any.metricId(base)); }
public Typed<T> mapBuilder(MapBuilder mapBuilder) { return any(any.mapBuilder(mapBuilder)); }
public Typed<T> loader(Loader<T> loader) { if (cache != null) { throw new IllegalStateException("shared cache is already set"); } return new Typed<T>(any, cache, loader, typedCacheBuilder); }