当前位置: 首页>>代码示例>>Java>>正文


Java PersistentUserManagedCache.put方法代码示例

本文整理汇总了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[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:23,代码来源:UserManagedCaches.java

示例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();
}
 
开发者ID:dzh,项目名称:jframe,代码行数:25,代码来源:TestUserManagedCache.java


注:本文中的org.ehcache.PersistentUserManagedCache.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。