本文整理汇总了Java中org.ehcache.PersistentUserManagedCache类的典型用法代码示例。如果您正苦于以下问题:Java PersistentUserManagedCache类的具体用法?Java PersistentUserManagedCache怎么用?Java PersistentUserManagedCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PersistentUserManagedCache类属于org.ehcache包,在下文中一共展示了PersistentUserManagedCache类的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();
}