FileSystemImpl(@Nonnull final File root) throws IOException { this.root = root; this.files = newBuilder().maximumSize(20) .build(new CacheLoader<String, FSFile>() { @Nonnull @Override public FSFile load(@Nonnull String path) throws IOException { return new FSFile(root, path); } }); util.createParentDirs(root); }
/** * Constructs a new {@code CacheBuilder} instance with default settings, including strong keys, * strong values, and no automatic eviction of any kind. */ @Nonnull public static CacheBuilder<Object, Object> newBuilder() { return new CacheBuilder<>(); }
@Nonnull public <K1 extends K, V1 extends V> Cache<K1, V1> build() { checkWeightWithWeigher(); checkNonLoadingCache(); return new LocalCache.LocalManualCache<>(this); }
@Nonnull CacheBuilder<K, V> recreateCacheBuilder() { CacheBuilder<K, V> builder = CacheBuilder.newBuilder() .setKeyStrength(keyStrength) .setValueStrength(valueStrength) .keyEquivalence(keyEquivalence) .valueEquivalence(valueEquivalence) .concurrencyLevel(concurrencyLevel) .removalListener(removalListener); builder.strictParsing = false; if (expireAfterWriteNanos > 0) { builder.expireAfterWrite(expireAfterWriteNanos, NANOSECONDS); builder.expireAfterAccess(expireAfterAccessNanos, NANOSECONDS); builder.weigher(weigher); if (maxWeight != UNSET_INT) { builder.maximumWeight(maxWeight); builder.maximumSize(maxWeight); builder.ticker(ticker);
AbstractCacheSet(ConcurrentMap<?, ?> map) { this.map = map; }
private void readObject(@Nonnull ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); CacheBuilder<K, V> builder = recreateCacheBuilder(); this.delegate = builder.build(); }
/** * Builds a cache, which either returns an already-loaded value for a given key or atomically * computes or retrieves it using the supplied {@code CacheLoader}. If another thread is currently * loading the value for this key, simply waits for that thread to finish and returns its * loaded value. Note that multiple threads can concurrently load values for distinct keys. * * <p>This method does not alter the state of this {@code CacheBuilder} instance, so it can be * invoked again to create multiple independent caches. * * @param loader the cache loader used to obtain new values * @return a cache having the requested features */ @Nonnull public <K1 extends K, V1 extends V> LoadingCache<K1, V1> build( @Nonnull CacheLoader<? super K1, V1> loader) { checkWeightWithWeigher(); return new LocalCache.LocalLoadingCache<>(this, loader); }
private void readObject(@Nonnull ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); CacheBuilder<K, V> builder = recreateCacheBuilder(); this.autoDelegate = builder.build(loader); }