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


Java Expirations类代码示例

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


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

示例1: newCacheConfigurationBuilder_oneExpiryThreeResourcePools

import org.ehcache.expiry.Expirations; //导入依赖的package包/类
@Test
public void newCacheConfigurationBuilder_oneExpiryThreeResourcePools() throws Exception {

    //given
    addProp(CacheConfigurationServiceImpl.PROP_KEY_SUFFIX_TIME_TO_IDLE_SECS,60);

    addProp(CacheConfigurationServiceImpl.PROP_KEY_SUFFIX_MAX_ENTRIES_HEAP,1);
    addProp(CacheConfigurationServiceImpl.PROP_KEY_SUFFIX_MAX_MB_OFF_HEAP,2);
    addProp(CacheConfigurationServiceImpl.PROP_KEY_SUFFIX_MAX_MB_DISK,3);

    //when

    CacheConfigurationBuilder<String,String> builder = cacheConfigurationService.newCacheConfigurationBuilder(CACHE_NAME, String.class, String.class);
    CacheConfiguration<String, String> cacheConfiguration = builder.build();

    //then
    assertThat(cacheConfiguration.getResourcePools().getResourceTypeSet().size()).isEqualTo(3);
    assertThat(cacheConfiguration.getExpiry()).isEqualTo(Expirations.timeToIdleExpiration(Duration.of(60, TimeUnit.SECONDS)));

}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:21,代码来源:TestCacheConfigurationService.java

示例2: createCache

import org.ehcache.expiry.Expirations; //导入依赖的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

示例3: cacheManager

import org.ehcache.expiry.Expirations; //导入依赖的package包/类
@Bean
public CacheManager cacheManager(@Autowired Config config) {
    long ttl = Long.valueOf(config.getProperties().getProperty(Config.PROP_CACHE_TTL));

    double pctOfHeap = Double.valueOf(config.getProperties().getProperty(Config.PROP_CACHE_SIZE));
    long cacheSizeMB = new Double(Runtime.getRuntime().maxMemory() * pctOfHeap / 1048576.0).longValue();

    LogFactory.getLog(getClass()).info(
            String.format("Initializing cache TTL=%d secs, size=%d MB (%.2f percent of max heap)",
                    ttl, cacheSizeMB, pctOfHeap * 100));

    org.ehcache.config.CacheConfiguration<Object, Object> cacheConfiguration = CacheConfigurationBuilder
            .newCacheConfigurationBuilder(Object.class, Object.class,
                    ResourcePoolsBuilder.newResourcePoolsBuilder()
                            .heap(cacheSizeMB, MemoryUnit.MB))
            .withExpiry(Expirations.timeToLiveExpiration(new org.ehcache.expiry.Duration(ttl, TimeUnit.SECONDS)))
            .build();

    Map<String, CacheConfiguration<?, ?>> caches = new HashMap<>();
    caches.put(CACHE_DEFAULT, cacheConfiguration);

    EhcacheCachingProvider provider = (EhcacheCachingProvider) javax.cache.Caching.getCachingProvider();

    // when our cacheManager bean is re-created several times for
    // diff test configurations, this provider seems to hang on to state
    // causing cache settings to not be right. so we always close().
    provider.close();

    DefaultConfiguration configuration = new DefaultConfiguration(
            caches, provider.getDefaultClassLoader());

    return new JCacheCacheManager(
            provider.getCacheManager(provider.getDefaultURI(), configuration));
}
 
开发者ID:codeforkjeff,项目名称:conciliator,代码行数:35,代码来源:Application.java

示例4: getCache

import org.ehcache.expiry.Expirations; //导入依赖的package包/类
@Override
public <K, V> Optional<Cache<K, V>> getCache(String name, Class<K> keyType, Class<V> valueType) {
	Cache<K, V> cache = null;
	Optional<CacheConfig> optionalCacheConfig = this.cacheConfigs.entrySet().stream().filter(entry -> {
		return entry.getValue().getCacheName().equals(name); }).map(entry -> { return entry.getValue(); }).findFirst();
	if (optionalCacheConfig.isPresent()) {
		org.ehcache.Cache<K, V> ehcache = this.cacheMgr.getCache(name, keyType, valueType);
		if (ehcache == null) {
			try {
				CacheConfig cacheConfig = optionalCacheConfig.get();
				Expiry<Object, Object> timeToLiveExpiration = Expirations
						.timeToLiveExpiration(new Duration((long) cacheConfig.getTtlSeconds(), TimeUnit.SECONDS));
				cache = new EhcacheCache<>(this.cacheMgr.createCache(cacheConfig.getCacheName(),
						CacheConfigurationBuilder
								.newCacheConfigurationBuilder(keyType, valueType, ResourcePoolsBuilder.heap(1000l))
								.withExpiry(timeToLiveExpiration).build()));
			} catch (Exception ex) {
				LOGGER.error("Could not get Cache with name: [{}], Exception!!", name, ex);
			}
		}
	} else {
		LOGGER.warn("CacheConfig against name [{}] doesn't exist, please create it first!", name);
	}
	return Optional.ofNullable(cache);
}
 
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:26,代码来源:EhcacheCacheProvider.java

示例5: createInMemoryCacheManager

import org.ehcache.expiry.Expirations; //导入依赖的package包/类
private CacheManager createInMemoryCacheManager() {
    long cacheSize = properties.getCache().getEhcache().getSize();
    long ttl = properties.getCache().getEhcache().getTimeToLiveSeconds();

    org.ehcache.config.CacheConfiguration<Object, Object> cacheConfiguration = CacheConfigurationBuilder
        .newCacheConfigurationBuilder(Object.class, Object.class, ResourcePoolsBuilder
            .newResourcePoolsBuilder()
            .heap(cacheSize))
        .withExpiry(Expirations.timeToLiveExpiration(new org.ehcache.expiry.Duration(ttl, TimeUnit.SECONDS)))
        .build();

    Map<String, org.ehcache.config.CacheConfiguration<?, ?>> caches = createCacheConfigurations(cacheConfiguration);

    EhcacheCachingProvider provider = getCachingProvider();
    DefaultConfiguration configuration = new DefaultConfiguration(caches, provider.getDefaultClassLoader());
    return provider.getCacheManager(provider.getDefaultURI(), configuration);
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:18,代码来源:CacheConfiguration.java

示例6: init

import org.ehcache.expiry.Expirations; //导入依赖的package包/类
@Before
public void init() {
    cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
            .withCache("preConfigured",
                    CacheConfigurationBuilder
                            .newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10))
                            .withExpiry(Expirations.timeToLiveExpiration(Duration.of(20, TimeUnit.SECONDS))))
            .build();
    cacheManager.init();

    // PersistentCacheManager persistentCacheManager =
    // CacheManagerBuilder.newCacheManagerBuilder()
    // .with(CacheManagerBuilder.persistence(getStoragePath() +
    // File.separator + "myData"))
    // .withCache("threeTieredCache",
    // CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class,
    // String.class,
    // ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10,
    // EntryUnit.ENTRIES)
    // .offheap(1, MemoryUnit.MB).disk(20, MemoryUnit.MB)))
    // .build(true);
    // persistentCacheManager.close();
}
 
开发者ID:dzh,项目名称:jframe,代码行数:24,代码来源:TestEhcache.java

示例7: CacheConfiguration

import org.ehcache.expiry.Expirations; //导入依赖的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

示例8: createCache

import org.ehcache.expiry.Expirations; //导入依赖的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

示例9: init

import org.ehcache.expiry.Expirations; //导入依赖的package包/类
protected void init(String namespace, Class valueType, long expire) {
    // TIPS: 实际应用中对于授权码缓存,只应该在缓存时间上进行控制
    manager = CacheManagerBuilder.newCacheManagerBuilder().withCache(
            namespace,
            CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, valueType, ResourcePoolsBuilder.heap(1024))
                    .withExpiry(Expirations.timeToLiveExpiration(Duration.of(expire, TimeUnit.MINUTES)))).build();
    manager.init();
}
 
开发者ID:procyon-lotor,项目名称:oauth4j,代码行数:9,代码来源:CacheSupport.java

示例10: InitEhcache

import org.ehcache.expiry.Expirations; //导入依赖的package包/类
@BeforeClass
public static void InitEhcache() {
    cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
            .withCache(NAME,
                    CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, ResourcePoolsBuilder.heap(10))
                            .withExpiry(Expirations.timeToLiveExpiration(Duration.of(6, TimeUnit.SECONDS))))
            .build();
    cacheManager.init();
}
 
开发者ID:dzh,项目名称:coca,代码行数:10,代码来源:TestCaEhcache.java

示例11: createClusteredCacheManager

import org.ehcache.expiry.Expirations; //导入依赖的package包/类
private CacheManager createClusteredCacheManager() {
    JHipsterProperties.Cache.Ehcache.Cluster clusterProperties = properties.getCache().getEhcache().getCluster();
    URI clusterUri = clusterProperties.getUri();
    boolean autoCreate = clusterProperties.isAutoCreate();
    long clusteredCacheSize = clusterProperties.getSizeInMb();
    Consistency consistency = clusterProperties.getConsistency();

    long heapCacheSize = properties.getCache().getEhcache().getSize();
    long ttl = properties.getCache().getEhcache().getTimeToLiveSeconds();

    ClusteringServiceConfigurationBuilder clusteringServiceConfigurationBuilder = ClusteringServiceConfigurationBuilder.cluster(clusterUri);
    ServerSideConfigurationBuilder serverSideConfigurationBuilder = (autoCreate ? clusteringServiceConfigurationBuilder.autoCreate() : clusteringServiceConfigurationBuilder.expecting())
        .defaultServerResource("primary-server-resource");

    org.ehcache.config.CacheConfiguration<Object, Object> cacheConfiguration = CacheConfigurationBuilder
        .newCacheConfigurationBuilder(Object.class, Object.class, ResourcePoolsBuilder
            .newResourcePoolsBuilder()
            .heap(heapCacheSize)
            .with(ClusteredResourcePoolBuilder.clusteredDedicated(clusteredCacheSize, MemoryUnit.MB)))
        .withExpiry(Expirations.timeToLiveExpiration(new org.ehcache.expiry.Duration(ttl, TimeUnit.SECONDS)))
        .add(new ClusteredStoreConfiguration(consistency)).build();

    Map<String, org.ehcache.config.CacheConfiguration<?, ?>> caches = createCacheConfigurations(cacheConfiguration);

    EhcacheCachingProvider provider = getCachingProvider();
    DefaultConfiguration configuration = new DefaultConfiguration(caches, provider.getDefaultClassLoader(), serverSideConfigurationBuilder.build());
    return provider.getCacheManager(provider.getDefaultURI(), configuration);
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:29,代码来源:CacheConfiguration.java

示例12: getCacheConfiguration

import org.ehcache.expiry.Expirations; //导入依赖的package包/类
private CacheConfiguration<String, ReplicationMessageList> getCacheConfiguration() {
    final long heapEntries = 10;

    return CacheConfigurationBuilder
            .newCacheConfigurationBuilder(
                    String.class,
                    ReplicationMessageList.class,
                    ResourcePoolsBuilder.heap(heapEntries))
            .withExpiry(Expirations.timeToLiveExpiration(
                    new Duration(CACHE_TIMEOUT, TimeUnit.MILLISECONDS)))
            .build();
}
 
开发者ID:dvoraka,项目名称:av-service,代码行数:13,代码来源:DefaultReplicationResponseClient.java

示例13: initAuthenticationCache

import org.ehcache.expiry.Expirations; //导入依赖的package包/类
private void initAuthenticationCache() {
    CacheConfiguration<String, Object> configuration = CacheConfigurationBuilder
            .newCacheConfigurationBuilder(String.class, Object.class, ResourcePoolsBuilder.heap(TWENTY_THOUSAND_ELEMENTS))
            .withExpiry(Expirations.timeToLiveExpiration(Duration.of(SIXTY, TimeUnit.MINUTES)))
            .build();

    registerCacheConfiguration(CacheName.AUTH.toString(), configuration);
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:9,代码来源:CacheProvider.java

示例14: initRequestCache

import org.ehcache.expiry.Expirations; //导入依赖的package包/类
private void initRequestCache() {
    CacheConfiguration<String, Object> configuration = CacheConfigurationBuilder
            .newCacheConfigurationBuilder(String.class, Object.class, ResourcePoolsBuilder.heap(FORTY_THOUSAND_ELEMENTS))
            .withExpiry(Expirations.timeToLiveExpiration(Duration.of(SIXTY, TimeUnit.SECONDS)))
            .build();

    registerCacheConfiguration(CacheName.REQUEST.toString(), configuration);
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:9,代码来源:CacheProvider.java

示例15: initServerEventCache

import org.ehcache.expiry.Expirations; //导入依赖的package包/类
private void initServerEventCache() {
    CacheConfiguration<String, Object> configuration = CacheConfigurationBuilder
            .newCacheConfigurationBuilder(String.class, Object.class, ResourcePoolsBuilder.heap(TWENTY_THOUSAND_ELEMENTS))
            .withExpiry(Expirations.timeToIdleExpiration(Duration.of(THIRTY, TimeUnit.MINUTES)))
            .build();

    registerCacheConfiguration(CacheName.SSE.toString(), configuration);
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:9,代码来源:CacheProvider.java


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