Java Code Examples for org.ehcache.config.builders.ResourcePoolsBuilder#disk()
The following examples show how to use
org.ehcache.config.builders.ResourcePoolsBuilder#disk() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheManagerProvider.java From TweetwallFX with MIT License | 5 votes |
private static ResourcePoolsBuilder addResource(final ResourcePoolsBuilder builder, final CacheResource cacheResource) { switch (cacheResource.getType()) { case DISK: return builder.disk(cacheResource.getAmount(), cacheResource.getUnit(), true); case HEAP: return builder.heap(cacheResource.getAmount(), EntryUnit.ENTRIES); case OFFHEAP: return builder.offheap(cacheResource.getAmount(), cacheResource.getUnit()); default: throw new IllegalStateException(CacheResourceType.class.getSimpleName() + "'" + cacheResource.getType() + "' is not supported!"); } }
Example 2
Source File: TranslateEhcacheManager.java From sagacity-sqltoy with Apache License 2.0 | 4 votes |
@Override public void put(TranslateConfigModel cacheConfig, String cacheName, String cacheKey, HashMap<String, Object[]> cacheValue) { if (cacheManager == null) { return; } synchronized (cacheName) { Cache<String, HashMap> cache = cacheManager.getCache(cacheName, String.class, HashMap.class); // 缓存没有配置,自动创建缓存(不建议使用) if (cache == null) { ResourcePoolsBuilder resBuilder = ResourcePoolsBuilder.newResourcePoolsBuilder(); // 堆内内存大小(20000条) resBuilder = resBuilder.heap((cacheConfig.getHeap() < 1) ? 1000 : cacheConfig.getHeap(), EntryUnit.ENTRIES); if (cacheConfig.getOffHeap() > 0) { resBuilder = resBuilder.offheap(cacheConfig.getOffHeap(), MemoryUnit.MB); } if (cacheConfig.getDiskSize() > 0) { resBuilder = resBuilder.disk(cacheConfig.getDiskSize(), MemoryUnit.MB, true); } cache = cacheManager.createCache(cacheName, CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, HashMap.class, resBuilder) .withExpiry(cacheConfig.getKeepAlive() > 0 ? ExpiryPolicyBuilder .timeToLiveExpiration(Duration.ofSeconds(cacheConfig.getKeepAlive())) : ExpiryPolicyBuilder.noExpiration()) .build()); } // 清除缓存(一般不会执行,即缓存值被设置为null表示清除缓存) if (cacheValue == null) { if (StringUtil.isBlank(cacheKey)) { cache.clear(); } else { cache.remove(cacheKey); } } // 更新缓存 else { cache.put(StringUtil.isBlank(cacheKey) ? cacheName : cacheKey, cacheValue); } } }
Example 3
Source File: EhCachePoolMixin.java From attic-polygene-java with Apache License 2.0 | 4 votes |
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 ); }
Example 4
Source File: EHCacheXKMSClientCache.java From cxf with Apache License 2.0 | 4 votes |
public EHCacheXKMSClientCache(Bus cxfBus, Path diskstorePath, long diskSize, long heapEntries, boolean persistent) throws XKMSClientCacheException { // Do some sanity checking on the arguments if (persistent && diskstorePath == null) { throw new NullPointerException(); } if (diskstorePath != null && (diskSize < 5 || diskSize > 10000)) { throw new IllegalArgumentException("The diskSize parameter must be between 5 and 10000 (megabytes)"); } if (heapEntries < 100) { throw new IllegalArgumentException("The heapEntries parameter must be greater than 100 (entries)"); } if (cxfBus == null) { cxfBus = BusFactory.getThreadDefaultBus(true); } if (cxfBus != null) { cxfBus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this); } this.bus = cxfBus; this.diskstorePath = diskstorePath; this.persistent = persistent; cacheKey = UUID.randomUUID().toString(); ResourcePoolsBuilder resourcePoolsBuilder = ResourcePoolsBuilder.newResourcePoolsBuilder() .heap(heapEntries, EntryUnit.ENTRIES); if (diskstorePath != null) { resourcePoolsBuilder = resourcePoolsBuilder.disk(diskSize, MemoryUnit.MB, persistent); } ExpiryPolicy<Object, Object> expiryPolicy = ExpiryPolicyBuilder.timeToLiveExpiration(Duration.of(3600, ChronoUnit.SECONDS)); CacheConfigurationBuilder<String, XKMSCacheToken> configurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder( String.class, XKMSCacheToken.class, resourcePoolsBuilder) .withExpiry(expiryPolicy); if (diskstorePath != null) { cacheManager = CacheManagerBuilder.newCacheManagerBuilder() .with(CacheManagerBuilder.persistence(diskstorePath.toFile())) .withCache(cacheKey, configurationBuilder) .build(); } else { cacheManager = CacheManagerBuilder.newCacheManagerBuilder() .withCache(cacheKey, configurationBuilder) .build(); } cacheManager.init(); cache = cacheManager.getCache(cacheKey, String.class, XKMSCacheToken.class); }