本文整理汇总了Java中org.ehcache.PersistentUserManagedCache.put方法的典型用法代码示例。如果您正苦于以下问题:Java PersistentUserManagedCache.put方法的具体用法?Java PersistentUserManagedCache.put怎么用?Java PersistentUserManagedCache.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ehcache.PersistentUserManagedCache
的用法示例。
在下文中一共展示了PersistentUserManagedCache.put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: userManagedDiskCache
import org.ehcache.PersistentUserManagedCache; //导入方法依赖的package包/类
@Test
public void userManagedDiskCache() throws Exception {
// tag::persistentUserManagedCache[]
LocalPersistenceService persistenceService = new DefaultLocalPersistenceService(new DefaultPersistenceConfiguration(new File(getStoragePath(), "myUserData"))); // <1>
PersistentUserManagedCache<Long, String> cache = UserManagedCacheBuilder.newUserManagedCacheBuilder(Long.class, String.class)
.with(new UserManagedPersistenceContext<>("cache-name", persistenceService)) // <2>
.withResourcePools(ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(10L, EntryUnit.ENTRIES)
.disk(10L, MemoryUnit.MB, true)) // <3>
.build(true);
// Work with the cache
cache.put(42L, "The Answer!");
assertThat(cache.get(42L), is("The Answer!"));
cache.close(); // <4>
cache.destroy(); // <5>
persistenceService.stop(); // <6>
// end::persistentUserManagedCache[]
}
示例2: persistenceServiceTest
import org.ehcache.PersistentUserManagedCache; //导入方法依赖的package包/类
public void persistenceServiceTest() {
LocalPersistenceService persistenceService = new DefaultLocalPersistenceService(
new DefaultPersistenceConfiguration(new File("", "myUserData")));
PersistentUserManagedCache<Long, String> cache = UserManagedCacheBuilder
.newUserManagedCacheBuilder(Long.class, String.class)
.with(new UserManagedPersistenceContext<Long, String>("cache-name", persistenceService))
.withResourcePools(ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10L, EntryUnit.ENTRIES).disk(10L,
MemoryUnit.MB, true))
.build(true);
// Work with the cache
cache.put(42L, "The Answer!");
// assertThat(cache.get(42L), is("The Answer!"));
cache.close();
try {
cache.destroy();
} catch (CachePersistenceException e) {
e.printStackTrace();
}
persistenceService.stop();
}