本文整理了Java中com.github.benmanes.caffeine.cache.Caffeine.softValues()
方法的一些代码示例,展示了Caffeine.softValues()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Caffeine.softValues()
方法的具体详情如下:
包路径:com.github.benmanes.caffeine.cache.Caffeine
类名称:Caffeine
方法名:softValues
[英]Specifies that each value (not key) stored in the cache should be wrapped in a SoftReference (by default, strong references are used). Softly-referenced objects will be garbage-collected in a globally least-recently-used manner, in response to memory demand.
Warning: in most circumstances it is better to set a per-cache #maximumSize(long) instead of using soft references. You should only use this method if you are very familiar with the practical consequences of soft references.
Note: when this method is used, the resulting cache will use identity ( ==) comparison to determine equality of values.
Entries with values that have been garbage collected may be counted in Cache#estimatedSize(), but will never be visible to read or write operations; such entries are cleaned up as part of the routine maintenance described in the class javadoc.
This feature cannot be used in conjunction with #buildAsync.
[中]指定缓存中存储的每个值(非键)都应包装在SoftReference中(默认情况下,使用强引用)。软引用对象将以全局最近最少使用的方式进行垃圾收集,以响应内存需求。
警告:在大多数情况下,最好设置每个缓存的最大大小(long),而不是使用软引用。只有当您非常熟悉软引用的实际后果时,才应该使用此方法。
注意:使用此方法时,生成的缓存将使用标识(=)比较来确定值的相等性。
具有已被垃圾收集的值的条目可能会在缓存#estimatedSize()中计数,但对读或写操作永远不会可见;这些条目作为javadoc类中描述的日常维护的一部分进行清理。
此功能不能与#buildAsync结合使用。
代码示例来源:origin: ben-manes/caffeine
@Test(expectedExceptions = IllegalStateException.class)
public void softValues_twice() {
Caffeine.newBuilder().softValues().softValues();
}
代码示例来源:origin: ben-manes/caffeine
@Test(expectedExceptions = IllegalStateException.class)
public void async_softValues() {
Caffeine.newBuilder().softValues().buildAsync(loader);
}
代码示例来源:origin: ben-manes/caffeine
@Test
public void softValues() {
Caffeine.newBuilder().softValues().build();
}
代码示例来源:origin: ben-manes/caffeine
@GwtIncompatible("weakValues")
public void testValueStrengthSetTwice() {
Caffeine<Object, Object> builder1 = Caffeine.newBuilder().weakValues();
try {
builder1.weakValues();
fail();
} catch (IllegalStateException expected) {}
try {
builder1.softValues();
fail();
} catch (IllegalStateException expected) {}
Caffeine<Object, Object> builder2 = Caffeine.newBuilder().softValues();
try {
builder2.softValues();
fail();
} catch (IllegalStateException expected) {}
try {
builder2.weakValues();
fail();
} catch (IllegalStateException expected) {}
}
代码示例来源:origin: ben-manes/caffeine
builder.weakValues();
} else if (valueStrength == Strength.SOFT) {
builder.softValues();
} else {
throw new IllegalStateException();
代码示例来源:origin: ben-manes/caffeine
builder.weakValues();
} else if (valueStrength == Strength.SOFT) {
builder.softValues();
代码示例来源:origin: ben-manes/caffeine
builder.softValues();
代码示例来源:origin: ben-manes/caffeine
public void testParse_softValues() {
CaffeineSpec spec = parse("softValues");
assertEquals(spec.initialCapacity, UNSET_INT);
assertEquals(spec.maximumSize, UNSET_INT);
assertEquals(spec.maximumWeight, UNSET_INT);
assertNull(spec.keyStrength);
assertEquals(Strength.SOFT, spec.valueStrength);
assertNull(spec.expireAfterWriteTimeUnit);
assertNull(spec.expireAfterAccessTimeUnit);
assertNull(spec.refreshAfterWriteTimeUnit);
assertCaffeineEquivalence(
Caffeine.newBuilder().softValues(), Caffeine.from(spec));
}
代码示例来源:origin: ben-manes/caffeine
public void testParse_whitespaceAllowed() {
CaffeineSpec spec = parse(" initialCapacity=10,\nmaximumSize=20,\t\r"
+ "weakKeys \t ,softValues \n , \r expireAfterWrite \t = 15s\n\n");
assertEquals(10, spec.initialCapacity);
assertEquals(20, spec.maximumSize);
assertEquals(spec.maximumWeight, UNSET_INT);
assertEquals(Strength.WEAK, spec.keyStrength);
assertEquals(Strength.SOFT, spec.valueStrength);
assertEquals(TimeUnit.SECONDS, spec.expireAfterWriteTimeUnit);
assertEquals(15L, spec.expireAfterWriteDuration);
assertNull(spec.expireAfterAccessTimeUnit);
Caffeine<?, ?> expected = Caffeine.newBuilder()
.initialCapacity(10)
.maximumSize(20)
.weakKeys()
.softValues()
.expireAfterWrite(15L, TimeUnit.SECONDS);
assertCaffeineEquivalence(expected, Caffeine.from(spec));
}
代码示例来源:origin: ben-manes/caffeine
builder.weakValues();
} else if (context.isSoftValues()) {
builder.softValues();
代码示例来源:origin: com.github.ben-manes.caffeine/caffeine
builder.weakValues();
} else if (valueStrength == Strength.SOFT) {
builder.softValues();
} else {
throw new IllegalStateException();
代码示例来源:origin: com.github.ben-manes.caffeine/caffeine
builder.softValues();
代码示例来源:origin: owlcs/owlapi
static <Q, T> LoadingCache<Q, T> build(CacheLoader<Q, T> c) {
return Caffeine.newBuilder().weakKeys().softValues().build(c);
}
代码示例来源:origin: net.sourceforge.owlapi/owlapi-impl
static <Q, T> LoadingCache<Q, T> build(CacheLoader<Q, T> c) {
return Caffeine.newBuilder().weakKeys().softValues().build(c);
}
代码示例来源:origin: net.sourceforge.owlapi/owlapi-distribution
static <Q, T> LoadingCache<Q, T> build(CacheLoader<Q, T> c) {
return Caffeine.newBuilder().weakKeys().softValues().build(c);
}
代码示例来源:origin: net.sourceforge.owlapi/owlapi-osgidistribution
static <Q, T> LoadingCache<Q, T> build(CacheLoader<Q, T> c) {
return Caffeine.newBuilder().weakKeys().softValues().build(c);
}
代码示例来源:origin: fr.inria.atlanmod.neoemf/neoemf-data-blueprints-core
/**
* Constructs a new {@code BlueprintsPersistenceBackend} wrapping the provided {@code baseGraph}.
* <p>
* This constructor initialize the caches and create the metaclass index.
* <p>
* This constructor is protected. To create a new {@code BlueprintsPersistenceBackend} use {@link
* BlueprintsPersistenceBackendFactory#createPersistentBackend(java.io.File, Map)}.
*
* @param baseGraph the base {@link KeyIndexableGraph} used to access the database
*
* @see BlueprintsPersistenceBackendFactory
*/
protected BlueprintsPersistenceBackend(KeyIndexableGraph baseGraph) {
this.graph = new AutoCleanerIdGraph(baseGraph);
this.persistentObjectsCache = Caffeine.newBuilder().softValues().build();
this.verticesCache = Caffeine.newBuilder().softValues().build();
this.indexedEClasses = new ArrayList<>();
Index<Vertex> metaclasses = graph.getIndex(KEY_METACLASSES, Vertex.class);
if (isNull(metaclasses)) {
metaclassIndex = graph.createIndex(KEY_METACLASSES, Vertex.class);
}
else {
metaclassIndex = metaclasses;
}
}
代码示例来源:origin: locationtech/geogig
CaffeineSharedCache(final int L1Capacity, Cache<CacheKey, byte[]> byteCache,
SizeTracker sizeTracker) {
this.L2Cache = byteCache;
this.sizeTracker = sizeTracker;
RemovalListener<CacheKey, RevObject> L1WriteBack = (key, value, cause) -> {
if (RemovalCause.SIZE == cause && value != null) {
putInternal(key, value);
}
};
this.L1Cache = Caffeine.newBuilder()//
.maximumSize(L1Capacity)//
.softValues()//
.removalListener(L1WriteBack)//
.build();
}
代码示例来源:origin: com.epam.reportportal/commons-dao
.newBuilder()
.maximumSize(ticketCacheSize)
.softValues()
.expireAfterAccess(ticketCacheExpiration, TimeUnit.MINUTES)
.build());
.newBuilder()
.maximumSize(projectCacheSize)
.softValues()
.expireAfterAccess(projectCacheExpiration, TimeUnit.DAYS)
.build());
.newBuilder()
.maximumSize(projectCacheSize)
.softValues()
.expireAfterWrite(projectInfoCacheExpiration, TimeUnit.MINUTES)
.build());
代码示例来源:origin: com.buschmais.jqassistant.plugin/java
/**
* Constructor.
*/
TypeCache() {
this.lruCache = Caffeine.newBuilder().maximumSize(8192).removalListener((RemovalListener<String, CachedType>) (key, value, cause) -> {
if (RemovalCause.SIZE.equals(cause)) {
softCache.put(key, value);
}
}).build();
this.softCache = Caffeine.newBuilder().softValues().build();
}
内容来源于网络,如有侵权,请联系作者删除!