• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Eh107Configuration类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: createCache

import org.ehcache.jsr107.Eh107Configuration; //导入依赖的package包/类
private void createCache(CacheManager cacheManager, String cacheName, Duration timeToLive, boolean persistentCache) {
	ResourcePoolsBuilder resourcePoolsBuilder = ResourcePoolsBuilder.heap(100);
	if (persistentCache) {
		resourcePoolsBuilder = resourcePoolsBuilder.disk(1, MemoryUnit.MB, true);
	}
	CacheConfiguration<Object, Object> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Object.class, Object.class,
		resourcePoolsBuilder)
		.withExpiry(Expirations.timeToLiveExpiration(timeToLive))
		.build();

	for (String cache : cacheManager.getCacheNames()) {
		if (cache.equals(cacheName)) {
			log.warn("cache '{}' already exists. skipping creation", cacheName);
			return;
		}
	}

	cacheManager.createCache(cacheName, Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfiguration));
}
 
开发者ID:cronn-de,项目名称:jira-sync,代码行数:20,代码来源:JiraServiceCacheConfig.java


示例2: testUsingEhcacheConfiguration

import org.ehcache.jsr107.Eh107Configuration; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testUsingEhcacheConfiguration() throws Exception {
  // tag::ehcacheBasedConfigurationExample[]
  CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
      ResourcePoolsBuilder.heap(10)).build(); // <1>

  Cache<Long, String> cache = cacheManager.createCache("myCache",
      Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfiguration)); // <2>

  Eh107Configuration<Long, String> configuration = cache.getConfiguration(Eh107Configuration.class);
  configuration.unwrap(CacheConfiguration.class); // <3>

  configuration.unwrap(CacheRuntimeConfiguration.class); // <4>

  try {
    cache.getConfiguration(CompleteConfiguration.class); // <5>
    throw new AssertionError("IllegalArgumentException expected");
  } catch (IllegalArgumentException iaex) {
    // Expected
  }
  // end::ehcacheBasedConfigurationExample[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:24,代码来源:EhCache107ConfigurationIntegrationDocTest.java


示例3: cacheConfigTest

import org.ehcache.jsr107.Eh107Configuration; //导入依赖的package包/类
@Test
public void cacheConfigTest() {
    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();

    MutableConfiguration<Long, String> configuration = new MutableConfiguration<Long, String>();
    configuration.setTypes(Long.class, String.class);
    Cache<Long, String> cache = cacheManager.createCache("someCache", configuration);

    CompleteConfiguration<Long, String> completeConfiguration = cache.getConfiguration(CompleteConfiguration.class);

    Eh107Configuration<Long, String> eh107Configuration = cache.getConfiguration(Eh107Configuration.class);

    CacheRuntimeConfiguration<Long, String> runtimeConfiguration = eh107Configuration
            .unwrap(CacheRuntimeConfiguration.class);
}
 
开发者ID:dzh,项目名称:jframe,代码行数:17,代码来源:TestJCache.java


示例4: configEhcache2Jsr107

import org.ehcache.jsr107.Eh107Configuration; //导入依赖的package包/类
@Test
public void configEhcache2Jsr107() {
    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();

    CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder
            .newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)).build();

    Cache<Long, String> cache = cacheManager.createCache("myCache",
            Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfiguration));

    Eh107Configuration<Long, String> configuration = cache.getConfiguration(Eh107Configuration.class);
    configuration.unwrap(CacheConfiguration.class);

    configuration.unwrap(CacheRuntimeConfiguration.class);

    try {
        cache.getConfiguration(CompleteConfiguration.class);
        throw new AssertionError("IllegalArgumentException expected");
    } catch (IllegalArgumentException iaex) {
        // Expected
    }
}
 
开发者ID:dzh,项目名称:jframe,代码行数:24,代码来源:TestJCache.java


示例5: CacheConfiguration

import org.ehcache.jsr107.Eh107Configuration; //导入依赖的package包/类
public CacheConfiguration(JHipsterProperties jHipsterProperties) {
    JHipsterProperties.Cache.Ehcache ehcache =
        jHipsterProperties.getCache().getEhcache();

    jcacheConfiguration = Eh107Configuration.fromEhcacheCacheConfiguration(
        CacheConfigurationBuilder.newCacheConfigurationBuilder(Object.class, Object.class,
            ResourcePoolsBuilder.heap(ehcache.getMaxEntries()))
            .withExpiry(Expirations.timeToLiveExpiration(Duration.of(ehcache.getTimeToLiveSeconds(), TimeUnit.SECONDS)))
            .build());
}
 
开发者ID:Microsoft,项目名称:MTC_Labrat,代码行数:11,代码来源:CacheConfiguration.java


示例6: inspectCacheConfig

import org.ehcache.jsr107.Eh107Configuration; //导入依赖的package包/类
private <K, V> void inspectCacheConfig(Cache<K, V> myJCache) {
  //get the configuration to print the size on heap
  CacheRuntimeConfiguration<K, V> ehcacheConfig = (CacheRuntimeConfiguration<K, V>) myJCache
    .getConfiguration(Eh107Configuration.class)
    .unwrap(CacheRuntimeConfiguration.class);
  long heapSize = ehcacheConfig.getResourcePools().getPoolForResource(ResourceType.Core.HEAP).getSize();
  LOGGER.info(ehcacheConfig.toString());
  LOGGER.info("Cache testing - Cache {} with heap capacity = {}", myJCache.getName(), heapSize);
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:10,代码来源:BaseJCacheTester.java


示例7: testGettingToEhcacheConfiguration

import org.ehcache.jsr107.Eh107Configuration; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testGettingToEhcacheConfiguration() {
  // tag::mutableConfigurationExample[]
  MutableConfiguration<Long, String> configuration = new MutableConfiguration<>();
  configuration.setTypes(Long.class, String.class);
  Cache<Long, String> cache = cacheManager.createCache("someCache", configuration); // <1>

  CompleteConfiguration<Long, String> completeConfiguration = cache.getConfiguration(CompleteConfiguration.class); // <2>

  Eh107Configuration<Long, String> eh107Configuration = cache.getConfiguration(Eh107Configuration.class); // <3>

  CacheRuntimeConfiguration<Long, String> runtimeConfiguration = eh107Configuration.unwrap(CacheRuntimeConfiguration.class); // <4>
  // end::mutableConfigurationExample[]
  assertThat(completeConfiguration, notNullValue());
  assertThat(runtimeConfiguration, notNullValue());

  // Check uses default JSR-107 expiry
  long nanoTime = System.nanoTime();
  LOGGER.info("Seeding random with {}", nanoTime);
  Random random = new Random(nanoTime);
  assertThat(runtimeConfiguration.getExpiryPolicy().getExpiryForCreation(random.nextLong(), Long.toOctalString(random.nextLong())),
              equalTo(org.ehcache.expiry.ExpiryPolicy.INFINITE));
  assertThat(runtimeConfiguration.getExpiryPolicy().getExpiryForAccess(random.nextLong(),
    () -> Long.toOctalString(random.nextLong())), nullValue());
  assertThat(runtimeConfiguration.getExpiryPolicy().getExpiryForUpdate(random.nextLong(),
    () -> Long.toOctalString(random.nextLong()), Long.toOctalString(random.nextLong())), nullValue());
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:29,代码来源:EhCache107ConfigurationIntegrationDocTest.java


示例8: testWithoutEhcacheExplicitDependencyAndNoCodeChanges

import org.ehcache.jsr107.Eh107Configuration; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testWithoutEhcacheExplicitDependencyAndNoCodeChanges() throws Exception {
  CacheManager manager = cachingProvider.getCacheManager(
      getClass().getResource("/org/ehcache/docs/ehcache-jsr107-template-override.xml").toURI(),
      getClass().getClassLoader());

  // tag::jsr107SupplementWithTemplatesExample[]
  MutableConfiguration<Long, Client> mutableConfiguration = new MutableConfiguration<>();
  mutableConfiguration.setTypes(Long.class, Client.class); // <1>

  Cache<Long, Client> anyCache = manager.createCache("anyCache", mutableConfiguration); // <2>

  CacheRuntimeConfiguration<Long, Client> ehcacheConfig = (CacheRuntimeConfiguration<Long, Client>)anyCache.getConfiguration(
      Eh107Configuration.class).unwrap(CacheRuntimeConfiguration.class); // <3>
  ehcacheConfig.getResourcePools().getPoolForResource(ResourceType.Core.HEAP).getSize(); // <4>

  Cache<Long, Client> anotherCache = manager.createCache("byRefCache", mutableConfiguration);
  assertFalse(anotherCache.getConfiguration(Configuration.class).isStoreByValue()); // <5>

  MutableConfiguration<String, Client> otherConfiguration = new MutableConfiguration<>();
  otherConfiguration.setTypes(String.class, Client.class);
  otherConfiguration.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ONE_MINUTE)); // <6>

  Cache<String, Client> foosCache = manager.createCache("foos", otherConfiguration);// <7>
  CacheRuntimeConfiguration<Long, Client> foosEhcacheConfig = (CacheRuntimeConfiguration<Long, Client>)foosCache.getConfiguration(
      Eh107Configuration.class).unwrap(CacheRuntimeConfiguration.class);
  Client client1 = new Client("client1", 1);
  foosEhcacheConfig.getExpiryPolicy().getExpiryForCreation(42L, client1).toMinutes(); // <8>

  CompleteConfiguration<String, String> foosConfig = foosCache.getConfiguration(CompleteConfiguration.class);

  try {
    final Factory<ExpiryPolicy> expiryPolicyFactory = foosConfig.getExpiryPolicyFactory();
    ExpiryPolicy expiryPolicy = expiryPolicyFactory.create(); // <9>
    throw new AssertionError("Expected UnsupportedOperationException");
  } catch (UnsupportedOperationException e) {
    // Expected
  }
  // end::jsr107SupplementWithTemplatesExample[]
  assertThat(ehcacheConfig.getResourcePools().getPoolForResource(ResourceType.Core.HEAP).getSize(), is(20L));
  assertThat(foosEhcacheConfig.getExpiryPolicy().getExpiryForCreation(42L, client1),
      is(java.time.Duration.ofMinutes(2)));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:45,代码来源:EhCache107ConfigurationIntegrationDocTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ReadOnlyException类代码示例发布时间:2022-05-21
下一篇:
Java FMLServerStoppingEvent类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap