• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java LocalManualCache类的典型用法和代码示例

java 3次浏览

本文整理汇总了Java中com.google.common.cache.LocalCache.LocalManualCache的典型用法代码示例。如果您正苦于以下问题:Java LocalManualCache类的具体用法?Java LocalManualCache怎么用?Java LocalManualCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

LocalManualCache类属于com.google.common.cache.LocalCache包,在下文中一共展示了LocalManualCache类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testSerializationProxyManual

点赞 2

import com.google.common.cache.LocalCache.LocalManualCache; //导入依赖的package包/类
public void testSerializationProxyManual() {
  RemovalListener<Object, Object> listener = new SerializableRemovalListener<Object, Object>();
  SerializableWeigher<Object, Object> weigher = new SerializableWeigher<Object, Object>();
  Ticker ticker = new SerializableTicker();
  @SuppressWarnings("unchecked") // createMock
  LocalManualCache<Object, Object> one = (LocalManualCache) CacheBuilder.newBuilder()
      .weakKeys()
      .softValues()
      .expireAfterAccess(123, NANOSECONDS)
      .maximumWeight(789)
      .weigher(weigher)
      .concurrencyLevel(12)
      .removalListener(listener)
      .ticker(ticker)
      .build();
  // add a non-serializable entry
  one.put(new Object(), new Object());
  assertEquals(1, one.size());
  assertFalse(one.asMap().isEmpty());
  LocalManualCache<Object, Object> two = SerializableTester.reserialize(one);
  assertEquals(0, two.size());
  assertTrue(two.asMap().isEmpty());

  LocalCache<Object, Object> localCacheOne = one.localCache;
  LocalCache<Object, Object> localCacheTwo = two.localCache;

  assertEquals(localCacheOne.keyStrength, localCacheTwo.keyStrength);
  assertEquals(localCacheOne.keyStrength, localCacheTwo.keyStrength);
  assertEquals(localCacheOne.valueEquivalence, localCacheTwo.valueEquivalence);
  assertEquals(localCacheOne.valueEquivalence, localCacheTwo.valueEquivalence);
  assertEquals(localCacheOne.maxWeight, localCacheTwo.maxWeight);
  assertEquals(localCacheOne.weigher, localCacheTwo.weigher);
  assertEquals(localCacheOne.expireAfterAccessNanos, localCacheTwo.expireAfterAccessNanos);
  assertEquals(localCacheOne.expireAfterWriteNanos, localCacheTwo.expireAfterWriteNanos);
  assertEquals(localCacheOne.removalListener, localCacheTwo.removalListener);
  assertEquals(localCacheOne.ticker, localCacheTwo.ticker);

  // serialize the reconstituted version to be sure we haven't lost the ability to reserialize
  LocalManualCache<Object, Object> three = SerializableTester.reserialize(two);
  LocalCache<Object, Object> localCacheThree = three.localCache;

  assertEquals(localCacheTwo.keyStrength, localCacheThree.keyStrength);
  assertEquals(localCacheTwo.keyStrength, localCacheThree.keyStrength);
  assertEquals(localCacheTwo.valueEquivalence, localCacheThree.valueEquivalence);
  assertEquals(localCacheTwo.valueEquivalence, localCacheThree.valueEquivalence);
  assertEquals(localCacheTwo.maxWeight, localCacheThree.maxWeight);
  assertEquals(localCacheTwo.weigher, localCacheThree.weigher);
  assertEquals(localCacheTwo.expireAfterAccessNanos, localCacheThree.expireAfterAccessNanos);
  assertEquals(localCacheTwo.expireAfterWriteNanos, localCacheThree.expireAfterWriteNanos);
  assertEquals(localCacheTwo.removalListener, localCacheThree.removalListener);
  assertEquals(localCacheTwo.ticker, localCacheThree.ticker);
}
 

开发者ID:zugzug90,
项目名称:guava-mock,
代码行数:53,
代码来源:LocalCacheTest.java

示例2: testSerializationProxyManual

点赞 2

import com.google.common.cache.LocalCache.LocalManualCache; //导入依赖的package包/类
public void testSerializationProxyManual() {
  RemovalListener<Object, Object> listener = new SerializableRemovalListener<>();
  SerializableWeigher<Object, Object> weigher = new SerializableWeigher<>();
  Ticker ticker = new SerializableTicker();
  @SuppressWarnings("unchecked") // createMock
  LocalManualCache<Object, Object> one =
      (LocalManualCache)
          CacheBuilder.newBuilder()
              .weakKeys()
              .softValues()
              .expireAfterAccess(123, NANOSECONDS)
              .maximumWeight(789)
              .weigher(weigher)
              .concurrencyLevel(12)
              .removalListener(listener)
              .ticker(ticker)
              .build();
  // add a non-serializable entry
  one.put(new Object(), new Object());
  assertEquals(1, one.size());
  assertFalse(one.asMap().isEmpty());
  LocalManualCache<Object, Object> two = SerializableTester.reserialize(one);
  assertEquals(0, two.size());
  assertTrue(two.asMap().isEmpty());

  LocalCache<Object, Object> localCacheOne = one.localCache;
  LocalCache<Object, Object> localCacheTwo = two.localCache;

  assertEquals(localCacheOne.keyStrength, localCacheTwo.keyStrength);
  assertEquals(localCacheOne.keyStrength, localCacheTwo.keyStrength);
  assertEquals(localCacheOne.valueEquivalence, localCacheTwo.valueEquivalence);
  assertEquals(localCacheOne.valueEquivalence, localCacheTwo.valueEquivalence);
  assertEquals(localCacheOne.maxWeight, localCacheTwo.maxWeight);
  assertEquals(localCacheOne.weigher, localCacheTwo.weigher);
  assertEquals(localCacheOne.expireAfterAccessNanos, localCacheTwo.expireAfterAccessNanos);
  assertEquals(localCacheOne.expireAfterWriteNanos, localCacheTwo.expireAfterWriteNanos);
  assertEquals(localCacheOne.removalListener, localCacheTwo.removalListener);
  assertEquals(localCacheOne.ticker, localCacheTwo.ticker);

  // serialize the reconstituted version to be sure we haven't lost the ability to reserialize
  LocalManualCache<Object, Object> three = SerializableTester.reserialize(two);
  LocalCache<Object, Object> localCacheThree = three.localCache;

  assertEquals(localCacheTwo.keyStrength, localCacheThree.keyStrength);
  assertEquals(localCacheTwo.keyStrength, localCacheThree.keyStrength);
  assertEquals(localCacheTwo.valueEquivalence, localCacheThree.valueEquivalence);
  assertEquals(localCacheTwo.valueEquivalence, localCacheThree.valueEquivalence);
  assertEquals(localCacheTwo.maxWeight, localCacheThree.maxWeight);
  assertEquals(localCacheTwo.weigher, localCacheThree.weigher);
  assertEquals(localCacheTwo.expireAfterAccessNanos, localCacheThree.expireAfterAccessNanos);
  assertEquals(localCacheTwo.expireAfterWriteNanos, localCacheThree.expireAfterWriteNanos);
  assertEquals(localCacheTwo.removalListener, localCacheThree.removalListener);
  assertEquals(localCacheTwo.ticker, localCacheThree.ticker);
}
 

开发者ID:google,
项目名称:guava,
代码行数:55,
代码来源:LocalCacheTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)