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


Java CacheConfigurationBuilder.withExpiry方法代码示例

本文整理汇总了Java中org.ehcache.config.builders.CacheConfigurationBuilder.withExpiry方法的典型用法代码示例。如果您正苦于以下问题:Java CacheConfigurationBuilder.withExpiry方法的具体用法?Java CacheConfigurationBuilder.withExpiry怎么用?Java CacheConfigurationBuilder.withExpiry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ehcache.config.builders.CacheConfigurationBuilder的用法示例。


在下文中一共展示了CacheConfigurationBuilder.withExpiry方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCache

import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
public void createCache(String title, Class keyType, Class<? extends Serializable> valueType, int heapMb,int timeToLiveSeconds,int timeToIdleSeconds) {
    CacheConfigurationBuilder builder = CacheConfigurationBuilder.newCacheConfigurationBuilder(keyType, valueType,
            ResourcePoolsBuilder.newResourcePoolsBuilder().heap(heapMb, MemoryUnit.MB)
    ) ;
    if(timeToLiveSeconds>10){
        builder = builder.withExpiry(Expirations.timeToLiveExpiration(Duration.of(timeToLiveSeconds, TimeUnit.SECONDS)));
    }
    if(timeToIdleSeconds>0){
        builder =  builder.withExpiry(Expirations.timeToIdleExpiration(Duration.of(timeToIdleSeconds, TimeUnit.SECONDS)));
    }
    cacheManager.createCache(title, builder.build());
    KEY_TYPE_MAP.put(title, keyType);
    VALUE_TYPE_MAP.put(title, valueType);
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:15,代码来源:EhCacheManager.java

示例2: createNewCache

import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
private <T> EhCacheImpl<T> createNewCache( String cacheId, Class<T> valueType )
{
    configuration.refresh();
    EhCacheConfiguration config = configuration.get();

    ResourcePoolsBuilder poolsBuilder = ResourcePoolsBuilder.newResourcePoolsBuilder();

    poolsBuilder = poolsBuilder.heap( config.heapSize().get(), MemoryUnit.valueOf( config.heapUnit().get() ) );

    if( config.offHeapSize().get() != null )
    {
        poolsBuilder = poolsBuilder.offheap( config.offHeapSize().get(),
                                             MemoryUnit.valueOf( config.offHeapUnit().get() ) );
    }
    if( config.diskSize().get() != null )
    {
        poolsBuilder = poolsBuilder.disk( config.diskSize().get(),
                                          MemoryUnit.valueOf( config.diskUnit().get() ),
                                          config.diskPersistent().get() );
    }

    CacheConfigurationBuilder<String, T> configBuilder = CacheConfigurationBuilder
        .newCacheConfigurationBuilder( String.class, valueType, poolsBuilder );
    if( config.maxObjectSize().get() != null )
    {
        configBuilder = configBuilder.withSizeOfMaxObjectSize( config.maxObjectSize().get(),
                                                               MemoryUnit.valueOf( config.maxObjectSizeUnit().get() ) );
    }
    if( config.maxObjectGraphDepth().get() != null )
    {
        configBuilder = configBuilder.withSizeOfMaxObjectGraph( config.maxObjectGraphDepth().get() );
    }
    switch( config.expiry().get() )
    {
        case "TIME_TO_IDLE":
            configBuilder = configBuilder.withExpiry( timeToIdleExpiration( Duration.of(
                config.expiryLength().get() == null ? - 1L : config.expiryLength().get(),
                TimeUnit.valueOf( config.expiryTimeUnit().get() ) ) ) );
            break;
        case "TIME_TO_LIVE":
            configBuilder = configBuilder.withExpiry( timeToLiveExpiration( Duration.of(
                config.expiryLength().get() == null ? - 1L : config.expiryLength().get(),
                TimeUnit.valueOf( config.expiryTimeUnit().get() ) ) ) );
            break;
        case "NONE":
        default:
            configBuilder = configBuilder.withExpiry( noExpiration() );
            break;
    }
    CacheConfiguration<String, T> cacheConfig = configBuilder.build();
    org.ehcache.Cache<String, T> cache = cacheManager.createCache( cacheId, cacheConfig );
    return new EhCacheImpl<>( cacheId, cache, valueType );
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:54,代码来源:EhCachePoolMixin.java

示例3: mergeConfigurations

import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
<K, V> ConfigHolder<K, V> mergeConfigurations(String cacheName, Configuration<K, V> configuration) {
  final Eh107CompleteConfiguration<K, V> jsr107Configuration = new Eh107CompleteConfiguration<>(configuration);

  Eh107Expiry<K, V> expiryPolicy = null;
  Jsr107CacheLoaderWriter<? super K, V> loaderWriter = null;
  try {
    CacheConfigurationBuilder<K, V> builder = newCacheConfigurationBuilder(configuration.getKeyType(), configuration.getValueType(), heap(Long.MAX_VALUE));

    String templateName = jsr107Service.getTemplateNameForCache(cacheName);
    if (xmlConfiguration != null && templateName != null) {
      CacheConfigurationBuilder<K, V> templateBuilder;
      try {
        templateBuilder = xmlConfiguration.newCacheConfigurationBuilderFromTemplate(templateName,
            jsr107Configuration.getKeyType(), jsr107Configuration.getValueType());
      } catch (IllegalStateException e) {
        templateBuilder = xmlConfiguration.newCacheConfigurationBuilderFromTemplate(templateName,
                      jsr107Configuration.getKeyType(), jsr107Configuration.getValueType(), heap(Long.MAX_VALUE));
      }
      if (templateBuilder != null) {
        builder = templateBuilder;
        LOG.info("Configuration of cache {} will be supplemented by template {}", cacheName, templateName);
      }
    }

    builder = handleStoreByValue(jsr107Configuration, builder, cacheName);

    final boolean hasConfiguredExpiry = builder.hasConfiguredExpiry();
    if (hasConfiguredExpiry) {
      LOG.info("Cache {} will use expiry configuration from template {}", cacheName, templateName);
    } else {
      expiryPolicy = initExpiryPolicy(jsr107Configuration);
      builder = builder.withExpiry(expiryPolicy);
    }

    boolean useEhcacheLoaderWriter;
    DefaultCacheLoaderWriterConfiguration ehcacheLoaderWriterConfiguration = builder.getExistingServiceConfiguration(DefaultCacheLoaderWriterConfiguration.class);
    if (ehcacheLoaderWriterConfiguration == null) {
      useEhcacheLoaderWriter = false;
      // No template loader/writer - let's activate the JSR-107 one if any
      loaderWriter = initCacheLoaderWriter(jsr107Configuration, new MultiCacheException());
      if (loaderWriter != null && (jsr107Configuration.isReadThrough() || jsr107Configuration.isWriteThrough())) {
        cacheLoaderWriterFactory.registerJsr107Loader(cacheName, loaderWriter);
      }
    } else {
      useEhcacheLoaderWriter = true;
      if (!jsr107Configuration.isReadThrough() && !jsr107Configuration.isWriteThrough()) {
        LOG.warn("Activating Ehcache loader/writer for JSR-107 cache {} which was neither read-through nor write-through", cacheName);
      }
      LOG.info("Cache {} will use loader/writer configuration from template {}", cacheName, templateName);
    }

    CacheConfiguration<K, V> cacheConfiguration = builder.build();

    setupManagementAndStatsInternal(jsr107Configuration, findSingletonAmongst(Jsr107CacheConfiguration.class, cacheConfiguration.getServiceConfigurations()));

    if (hasConfiguredExpiry) {
      expiryPolicy = new EhcacheExpiryWrapper<>(cacheConfiguration.getExpiryPolicy());
    }

    return new ConfigHolder<>(
      new CacheResources<>(cacheName, loaderWriter, expiryPolicy, initCacheEventListeners(jsr107Configuration)),
      new Eh107CompleteConfiguration<>(jsr107Configuration, cacheConfiguration, hasConfiguredExpiry, useEhcacheLoaderWriter),
      cacheConfiguration, useEhcacheLoaderWriter);
  } catch (Throwable throwable) {
    MultiCacheException mce = new MultiCacheException();
    CacheResources.close(expiryPolicy, mce);
    CacheResources.close(loaderWriter, mce);

    if (throwable instanceof IllegalArgumentException) {
      String message = throwable.getMessage();
      if (mce.getMessage() != null) {
        message = message + "\nSuppressed " + mce.getMessage();
      }
      throw new IllegalArgumentException(message, throwable);
    }
    mce.addFirstThrowable(throwable);
    throw mce;
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:80,代码来源:ConfigurationMerger.java


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