本文整理汇总了Java中org.ehcache.Cache.replace方法的典型用法代码示例。如果您正苦于以下问题:Java Cache.replace方法的具体用法?Java Cache.replace怎么用?Java Cache.replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ehcache.Cache
的用法示例。
在下文中一共展示了Cache.replace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testOffHeapClientClass
import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testOffHeapClientClass() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withClassLoader(getClass().getClassLoader())
.withCache("myCache", newCacheConfigurationBuilder(Long.class, Order.class, newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES).offheap(2, MemoryUnit.MB))
.build())
.build(true);
Cache<Long, Order> cache = cacheManager.getCache("myCache", Long.class, Order.class);
Order order = new Order(42L);
cache.put(42L, order);
assertTrue(cache.get(42L) instanceof Order);
cache.replace(42L, order, new Order(-1L));
assertEquals(-1L, cache.get(42L).id);
}
示例2: testOverSizedObjectPutFailsWithOnHeapAsAuthority
import org.ehcache.Cache; //导入方法依赖的package包/类
@Test
public void testOverSizedObjectPutFailsWithOnHeapAsAuthority() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withDefaultSizeOfMaxObjectSize(500, MemoryUnit.B).build(true);
CacheConfiguration<String, String> cacheConfiguration = CacheConfigurationBuilder
.newCacheConfigurationBuilder(String.class, String.class,
newResourcePoolsBuilder()
.heap(100, MemoryUnit.KB).build())
.build();
Cache<String, String> cache = cacheManager.createCache("cache",
cacheConfiguration);
cache.put("key1", getOverSizedObject());
assertThat(cache.get("key1"), nullValue());
cache.put("key1", "value1");
cache.replace("key1", getOverSizedObject());
assertThat(cache.get("key1"), nullValue());
}