Tabnine Logo
com.google.common.cache
Code IndexAdd Tabnine to your IDE (free)

How to use com.google.common.cache

Best Java code snippets using com.google.common.cache (Showing top 20 results out of 9,909)

origin: google/guava

void reclaimValue(ValueReference<K, V> valueReference) {
 ReferenceEntry<K, V> entry = valueReference.getEntry();
 int hash = entry.getHash();
 segmentFor(hash).reclaimValue(entry.getKey(), hash, valueReference);
}
origin: google/guava

public void testEviction_setMaxSegmentWeight() {
 IdentityLoader<Object> loader = identityLoader();
 for (int i = 1; i < 1000; i++) {
  LoadingCache<Object, Object> cache =
    CacheBuilder.newBuilder().maximumWeight(i).weigher(constantWeigher(1)).build(loader);
  assertEquals(i, CacheTesting.getTotalSegmentSize(cache));
 }
}
origin: google/guava

public void testEviction_setMaxSegmentSize() {
 IdentityLoader<Object> loader = identityLoader();
 for (int i = 1; i < 1000; i++) {
  LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().maximumSize(i).build(loader);
  assertEquals(i, CacheTesting.getTotalSegmentSize(cache));
 }
}
origin: google/guava

public void testParse_writeExpirationHours() {
 CacheBuilderSpec spec = parse("expireAfterWrite=150h");
 assertEquals(TimeUnit.HOURS, spec.writeExpirationTimeUnit);
 assertEquals(150L, spec.writeExpirationDuration);
 assertCacheBuilderEquivalence(
   CacheBuilder.newBuilder().expireAfterWrite(150L, TimeUnit.HOURS), CacheBuilder.from(spec));
}
origin: google/guava

public void testParse_accessExpirationSeconds() {
 CacheBuilderSpec spec = parse("expireAfterAccess=10s");
 assertEquals(TimeUnit.SECONDS, spec.accessExpirationTimeUnit);
 assertEquals(10L, spec.accessExpirationDuration);
 assertCacheBuilderEquivalence(
   CacheBuilder.newBuilder().expireAfterAccess(10L, TimeUnit.SECONDS),
   CacheBuilder.from(spec));
}
origin: google/guava

public void testParse_recordStats() {
 CacheBuilderSpec spec = parse("recordStats");
 assertTrue(spec.recordStats);
 assertCacheBuilderEquivalence(CacheBuilder.newBuilder().recordStats(), CacheBuilder.from(spec));
}
origin: google/guava

public void testParse_softValues() {
 CacheBuilderSpec spec = parse("softValues");
 assertNull(spec.initialCapacity);
 assertNull(spec.maximumSize);
 assertNull(spec.maximumWeight);
 assertNull(spec.concurrencyLevel);
 assertNull(spec.keyStrength);
 assertEquals(Strength.SOFT, spec.valueStrength);
 assertNull(spec.writeExpirationTimeUnit);
 assertNull(spec.accessExpirationTimeUnit);
 assertCacheBuilderEquivalence(CacheBuilder.newBuilder().softValues(), CacheBuilder.from(spec));
}
origin: google/guava

public void testParse_weakKeys() {
 CacheBuilderSpec spec = parse("weakKeys");
 assertNull(spec.initialCapacity);
 assertNull(spec.maximumSize);
 assertNull(spec.maximumWeight);
 assertNull(spec.concurrencyLevel);
 assertEquals(Strength.WEAK, spec.keyStrength);
 assertNull(spec.valueStrength);
 assertNull(spec.writeExpirationTimeUnit);
 assertNull(spec.accessExpirationTimeUnit);
 assertCacheBuilderEquivalence(CacheBuilder.newBuilder().weakKeys(), CacheBuilder.from(spec));
}
origin: google/guava

public void testParse_weakValues() {
 CacheBuilderSpec spec = parse("weakValues");
 assertNull(spec.initialCapacity);
 assertNull(spec.maximumSize);
 assertNull(spec.maximumWeight);
 assertNull(spec.concurrencyLevel);
 assertNull(spec.keyStrength);
 assertEquals(Strength.WEAK, spec.valueStrength);
 assertNull(spec.writeExpirationTimeUnit);
 assertNull(spec.accessExpirationTimeUnit);
 assertCacheBuilderEquivalence(CacheBuilder.newBuilder().weakValues(), CacheBuilder.from(spec));
}
origin: google/guava

public void testParse_empty() {
 CacheBuilderSpec spec = parse("");
 assertNull(spec.initialCapacity);
 assertNull(spec.maximumSize);
 assertNull(spec.maximumWeight);
 assertNull(spec.concurrencyLevel);
 assertNull(spec.keyStrength);
 assertNull(spec.valueStrength);
 assertNull(spec.writeExpirationTimeUnit);
 assertNull(spec.accessExpirationTimeUnit);
 assertCacheBuilderEquivalence(CacheBuilder.newBuilder(), CacheBuilder.from(spec));
}
origin: google/guava

public void testInvalidateAll_empty() {
 for (LoadingCache<Object, Object> cache : caches()) {
  cache.getUnchecked("a");
  cache.getUnchecked("b");
  cache.getUnchecked("c");
  cache.invalidateAll();
  checkEmpty(cache);
 }
}
origin: google/guava

public void testGet_null() throws ExecutionException {
 for (LoadingCache<Object, Object> cache : caches()) {
  try {
   cache.get(null);
   fail("Expected NullPointerException");
  } catch (NullPointerException expected) {
  }
  checkEmpty(cache);
 }
}
origin: google/guava

public void testGetUnchecked_null() {
 for (LoadingCache<Object, Object> cache : caches()) {
  try {
   cache.getUnchecked(null);
   fail("Expected NullPointerException");
  } catch (NullPointerException expected) {
  }
  checkEmpty(cache);
 }
}
origin: google/guava

static <K, V> void assertNotified(
  QueuingRemovalListener<K, V> listener, K key, V value, RemovalCause cause) {
 RemovalNotification<K, V> notification = listener.remove();
 assertSame(key, notification.getKey());
 assertSame(value, notification.getValue());
 assertSame(cause, notification.getCause());
}
origin: google/guava

public void testSize_populated() {
 for (LoadingCache<Object, Object> cache : caches()) {
  // don't let the entries get GCed
  List<Entry<Object, Object>> warmed = warmUp(cache);
  assertEquals(WARMUP_SIZE, cache.size());
  assertMapSize(cache.asMap(), WARMUP_SIZE);
  checkValidState(cache);
 }
}
origin: google/guava

public void testGetOrDefault() {
 LocalCache<Object, Object> map =
   makeLocalCache(createCacheBuilder().concurrencyLevel(1).initialCapacity(1));
 map.put(1, 1);
 assertEquals(1, map.getOrDefault(1, 2));
 assertEquals(2, map.getOrDefault(2, 2));
}
origin: google/guava

public void testSetRemovalListener() {
 RemovalListener<Object, Object> testListener = TestingRemovalListeners.nullRemovalListener();
 LocalCache<Object, Object> map =
   makeLocalCache(createCacheBuilder().removalListener(testListener));
 assertSame(testListener, map.removalListener);
}
origin: google/guava

private static <K, V> void assertConnected(
  LocalCache<K, V> map, ReferenceEntry<K, V> one, ReferenceEntry<K, V> two) {
 if (map.usesWriteQueue()) {
  assertSame(two, one.getNextInWriteQueue());
 }
 if (map.usesAccessQueue()) {
  assertSame(two, one.getNextInAccessQueue());
 }
}
origin: google/guava

public void testParse_writeExpirationMinutes() {
 CacheBuilderSpec spec = parse("expireAfterWrite=10m");
 assertEquals(TimeUnit.MINUTES, spec.writeExpirationTimeUnit);
 assertEquals(10L, spec.writeExpirationDuration);
 assertCacheBuilderEquivalence(
   CacheBuilder.newBuilder().expireAfterWrite(10L, TimeUnit.MINUTES), CacheBuilder.from(spec));
}
origin: google/guava

public void testParse_accessExpirationMinutes() {
 CacheBuilderSpec spec = parse("expireAfterAccess=10m");
 assertEquals(TimeUnit.MINUTES, spec.accessExpirationTimeUnit);
 assertEquals(10L, spec.accessExpirationDuration);
 assertCacheBuilderEquivalence(
   CacheBuilder.newBuilder().expireAfterAccess(10L, TimeUnit.MINUTES),
   CacheBuilder.from(spec));
}
com.google.common.cache

Most used classes

  • CacheBuilder
    A builder of LoadingCache and Cache instances having any combination of the following features: * au
  • LoadingCache
    A semi-persistent mapping from keys to values. Values are automatically loaded by the cache, and are
  • Cache
    A semi-persistent mapping from keys to values. Cache entries are manually added using #get(Object,Ca
  • RemovalNotification
    A notification of the removal of a single entry. The key and/or value may be null if they were alrea
  • CacheLoader
    Computes or retrieves values, based on a key, for use in populating a LoadingCache.Most implementati
  • RemovalCause,
  • CacheBuilderSpec,
  • CacheLoader$InvalidCacheLoadException,
  • Weigher,
  • RemovalListener,
  • AbstractCache$SimpleStatsCounter,
  • AbstractCache$StatsCounter,
  • LocalCache$Strength,
  • LocalCache$EntryFactory,
  • LocalCache$LoadingValueReference,
  • LocalCache$LocalLoadingCache,
  • LocalCache$LocalManualCache,
  • LocalCache$Segment,
  • LocalCache$ValueReference
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now