Usages of

com.google.common.cache.Weigher.weigh(?, ?)
CacheLIRS(Weigher<K, V> weigher, long maxMemory, int averageMemory, // code omitted ... /** * Get the size of the given value. The default implementation returns the * average memory as configured for this cache. * * @param key the key * @param value the value * @return the size */ protected int sizeOf(K key, V value) { if (weigher == null) { return averageMemory; } return weigher.weigh(key, value); }
CacheLIRS(Weigher<K, V> weigher, long maxMemory, int averageMemory, // code omitted ... /** * Get the size of the given value. The default implementation returns the * average memory as configured for this cache. * * @param key the key * @param value the value * @return the size */ protected int sizeOf(K key, V value) { if (weigher == null) { return averageMemory; } return weigher.weigh(key, value); }
public WindmillStateCache() { final Weigher<Weighted, Weighted> weigher = Weighers.weightedKeysAndValues(); stateCache = CacheBuilder.newBuilder() .maximumWeight(100000000 /* 100 MB */) .recordStats() .weigher(weigher) .removalListener(new RemovalListener<StateId, StateCacheEntry>() { @Override public void onRemoval(RemovalNotification<StateId, StateCacheEntry> removal) { if (removal.getCause() != RemovalCause.REPLACED) { weight -= weigher.weigh(removal.getKey(), removal.getValue()); } } }) .build(); }
public FileCacheStats(Cache<?, ?> cache, Weigher<?, ?> weigher, Weigher<?, ?> memWeigher, // code omitted ... @Override public long estimateCurrentMemoryWeight() { if (memWeigher == null) { return -1; } long size = 0; for (Map.Entry<?, ?> e : cache.asMap().entrySet()) { Object k = e.getKey(); Object v = e.getValue(); size += memWeigher.weigh(k, v); } return size; }
Weigher<?, ?> weigher, long maxWeight) { // code omitted ... @Override public long estimateCurrentWeight() { if (weigher == null) { return -1; } long size = 0; for (Map.Entry<?, ?> e : cache.asMap().entrySet()) { Object k = e.getKey(); Object v = e.getValue(); size += weigher.weigh(k, v); } return size; }
Default(final int size, @Nonnull final Weigher<T, RecordId> weigher) { this.weigher = checkNotNull(weigher); records = new LinkedHashMap<T, RecordId>(size * 4 / 3, 0.75f, true) { @Override protected boolean removeEldestEntry(Map.Entry<T, RecordId> eldest) { boolean remove = super.size() > size; if (remove) { Default.super.evictionCount++; weight -= weigher.weigh(eldest.getKey(), eldest.getValue()); } return remove; } }; }
public PriorityCache(int size, @Nonnull Weigher<K, V> weigher) { // code omitted ... @SuppressWarnings("unchecked") private int weighEntry(Entry<?, ?> entry) { return weigher.weigh((K) entry.key, (V) entry.value); }
public EntryWeiterAdpter(Weigher<? super K, ? super V> weigher) { // code omitted ... @Override public int weightOf(K key, V value) { return weigher.weigh(key, value); }
EntryWeigherAdapter(Weigher<? super K, ? super V> weigher) { // code omitted ... public int weightOf(K key, V value) { return weigher.weigh(key, value); }
/** Creates the denormalized cache of resources based on the builder configuration. */ Cache<ResourceKey<K>, R> __makeCache(MultiwayPoolBuilder<? super K, ? super R> builder) { CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder(); if (builder.maximumSize != MultiwayPoolBuilder.UNSET_INT) { cacheBuilder.maximumSize(builder.maximumSize); } if (builder.maximumWeight != MultiwayPoolBuilder.UNSET_INT) { cacheBuilder.maximumWeight(builder.maximumWeight); } if (builder.weigher != null) { final Weigher<? super K, ? super R> weigher = builder.weigher; cacheBuilder.weigher(new Weigher<ResourceKey<K>, R>() { @Override public int weigh(ResourceKey<K> resourceKey, R resource) { return weigher.weigh(resourceKey.getKey(), resource); } }); } if (builder.expireAfterWriteNanos != MultiwayPoolBuilder.UNSET_INT) { cacheBuilder.expireAfterWrite(builder.expireAfterWriteNanos, TimeUnit.NANOSECONDS); } if (builder.ticker != null) { cacheBuilder.ticker(builder.ticker); } if (builder.recordStats) { cacheBuilder.recordStats(); } cacheBuilder.concurrencyLevel(builder.getConcurrencyLevel()); cacheBuilder.removalListener(new CacheRemovalListener()); return cacheBuilder.build(); }
Usage snippet has been bookmarked! Review your bookmarks
Thank you! Review your likes