net.sf.ehcache.config.CacheConfiguration Java Examples

The following examples show how to use net.sf.ehcache.config.CacheConfiguration. 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 Project: J2Cache   Author: oschina   File: EhCacheProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public EhCache buildCache(String region, long timeToLiveInSeconds, CacheExpiredListener listener) {
    EhCache ehcache = caches.computeIfAbsent(region, v -> {
        //配置缓存
        CacheConfiguration cfg = manager.getConfiguration().getDefaultCacheConfiguration().clone();
        cfg.setName(region);
        if(timeToLiveInSeconds > 0) {
            cfg.setTimeToLiveSeconds(timeToLiveInSeconds);
            cfg.setTimeToIdleSeconds(timeToLiveInSeconds);
        }

        net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(cfg);
        manager.addCache(cache);

        log.info("Started Ehcache region [{}] with TTL: {}", region, timeToLiveInSeconds);

        return new EhCache(cache, listener);
    });

    if (ehcache.ttl() != timeToLiveInSeconds)
        throw new IllegalArgumentException(String.format("Region [%s] TTL %d not match with %d", region, ehcache.ttl(), timeToLiveInSeconds));

    return ehcache;
}
 
Example #2
Source Project: springboot-shiro-cas-mybatis   Author: hsj-xiaokang   File: EhCacheTicketRegistry.java    License: MIT License 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
    if (this.serviceTicketsCache == null || this.ticketGrantingTicketsCache == null) {
        throw new BeanInstantiationException(this.getClass(),
                "Both serviceTicketsCache and ticketGrantingTicketsCache are required properties.");
    }

    if (logger.isDebugEnabled()) {
        CacheConfiguration config = this.serviceTicketsCache.getCacheConfiguration();
        logger.debug("serviceTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap());
        logger.debug("serviceTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk());
        logger.debug("serviceTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk());
        logger.debug("serviceTicketsCache.timeToLive={}", config.getTimeToLiveSeconds());
        logger.debug("serviceTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds());
        logger.debug("serviceTicketsCache.cacheManager={}", this.serviceTicketsCache.getCacheManager().getName());

        config = this.ticketGrantingTicketsCache.getCacheConfiguration();
        logger.debug("ticketGrantingTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap());
        logger.debug("ticketGrantingTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk());
        logger.debug("ticketGrantingTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk());
        logger.debug("ticketGrantingTicketsCache.timeToLive={}", config.getTimeToLiveSeconds());
        logger.debug("ticketGrantingTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds());
        logger.debug("ticketGrantingTicketsCache.cacheManager={}", this.ticketGrantingTicketsCache.getCacheManager()
                .getName());
    }
}
 
Example #3
Source Project: cas4.0.x-server-wechat   Author: luotuo   File: EhCacheTicketRegistry.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
    if (this.serviceTicketsCache == null || this.ticketGrantingTicketsCache == null) {
        throw new BeanInstantiationException(this.getClass(),
                "Both serviceTicketsCache and ticketGrantingTicketsCache are required properties.");
    }

    if (logger.isDebugEnabled()) {
        CacheConfiguration config = this.serviceTicketsCache.getCacheConfiguration();
        logger.debug("serviceTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap());
        logger.debug("serviceTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk());
        logger.debug("serviceTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk());
        logger.debug("serviceTicketsCache.timeToLive={}", config.getTimeToLiveSeconds());
        logger.debug("serviceTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds());
        logger.debug("serviceTicketsCache.cacheManager={}", this.serviceTicketsCache.getCacheManager().getName());

        config = this.ticketGrantingTicketsCache.getCacheConfiguration();
        logger.debug("ticketGrantingTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap());
        logger.debug("ticketGrantingTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk());
        logger.debug("ticketGrantingTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk());
        logger.debug("ticketGrantingTicketsCache.timeToLive={}", config.getTimeToLiveSeconds());
        logger.debug("ticketGrantingTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds());
        logger.debug("ticketGrantingTicketsCache.cacheManager={}", this.ticketGrantingTicketsCache.getCacheManager()
                .getName());
    }
}
 
Example #4
Source Project: Mycat2   Author: MyCATApache   File: EnchachePooFactory.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public CachePool createCachePool(String poolName, int cacheSize,
		int expiredSeconds) {
	CacheManager cacheManager = CacheManager.create();
	Cache enCache = cacheManager.getCache(poolName);
	if (enCache == null) {

		CacheConfiguration cacheConf = cacheManager.getConfiguration()
				.getDefaultCacheConfiguration().clone();
		cacheConf.setName(poolName);
		if (cacheConf.getMaxEntriesLocalHeap() != 0) {
			cacheConf.setMaxEntriesLocalHeap(cacheSize);
		} else {
			cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize));
		}
		cacheConf.setTimeToIdleSeconds(expiredSeconds);
		Cache cache = new Cache(cacheConf);
		cacheManager.addCache(cache);
		return new EnchachePool(poolName,cache,cacheSize);
	} else {
		return new EnchachePool(poolName,enCache,cacheSize);
	}
}
 
Example #5
Source Project: dble   Author: actiontech   File: EnchachePooFactory.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public CachePool createCachePool(String poolName, int cacheSize,
                                 int expiredSeconds) {
    CacheManager cacheManager = CacheManager.create();
    Cache enCache = cacheManager.getCache(poolName);
    if (enCache == null) {

        CacheConfiguration cacheConf = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone();
        cacheConf.setName(poolName);
        if (cacheConf.getMaxEntriesLocalHeap() != 0) {
            cacheConf.setMaxEntriesLocalHeap(cacheSize);
        } else {
            cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize));
        }
        cacheConf.setTimeToIdleSeconds(expiredSeconds);
        Cache cache = new Cache(cacheConf);
        cacheManager.addCache(cache);
        return new EnchachePool(poolName, cache, cacheSize);
    } else {
        return new EnchachePool(poolName, enCache, cacheSize);
    }
}
 
Example #6
Source Project: jpress   Author: JPressProjects   File: EhcacheManager.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void init() {

        Configuration config = ConfigurationFactory.parseConfiguration();
        config.setClassLoader(ehcacheClassloader);

        String maxBytesLocalHeap = JbootConfigManager.me().getConfigValue("jpress.ehcache.maxBytesLocalHeap");
        config.setMaxBytesLocalHeap(StrUtil.obtainDefaultIfBlank(maxBytesLocalHeap, "100M"));

        String maxBytesLocalDisk = JbootConfigManager.me().getConfigValue("jpress.ehcache.maxBytesLocalDisk");
        config.setMaxBytesLocalDisk(StrUtil.obtainDefaultIfBlank(maxBytesLocalDisk, "5G"));

        CacheConfiguration cacheConfiguration = new CacheConfiguration();
        cacheConfiguration.setClassLoader(ehcacheClassloader);
        config.defaultCache(cacheConfiguration);

        CacheManager.create(config);
    }
 
Example #7
/**
 * 使用特定的配置添加缓存
 */
@Test
public void addAndRemove03() {
	CacheManager manager = CacheManager.create();

	// 添加缓存
	Cache testCache = new Cache(new CacheConfiguration("testCache3", 5000)
		.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU).eternal(false).timeToLiveSeconds(60)
		.timeToIdleSeconds(30).diskExpiryThreadIntervalSeconds(0)
		.persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP)));
	manager.addCache(testCache);

	// 打印配置信息和状态
	Cache test = manager.getCache("testCache3");
	System.out.println("cache name:" + test.getCacheConfiguration().getName());
	System.out.println("cache status:" + test.getStatus().toString());
	System.out.println("maxElementsInMemory:" + test.getCacheConfiguration().getMaxElementsInMemory());
	System.out.println("timeToIdleSeconds:" + test.getCacheConfiguration().getTimeToIdleSeconds());
	System.out.println("timeToLiveSeconds:" + test.getCacheConfiguration().getTimeToLiveSeconds());

	// 删除缓存
	manager.removeCache("testCache3");
	System.out.println("cache status:" + test.getStatus().toString());
}
 
Example #8
Source Project: hesperides   Author: voyages-sncf-technologies   File: CachedParentLdapGroupAuthorityRetrieverTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Before
public void setUp() {
    parentGroupsTree = new HashMap<>();
    cache = new Cache(new CacheConfiguration(TEST_GROUPS_TREE_CACHE_NAME, 5000)
            .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
            .timeToLiveSeconds(2)
            .diskPersistent(false)
            .eternal(false)
            .overflowToDisk(false));
    if (cacheManager.cacheExists(TEST_GROUPS_TREE_CACHE_NAME)) {
        cacheManager.removeCache(TEST_GROUPS_TREE_CACHE_NAME);
    }
    cacheManager.addCache(cache);
    cachedParentLdapGroupAuthorityRetriever = new CachedParentLdapGroupAuthorityRetriever(cache);
    cachedParentLdapGroupAuthorityRetriever.setParentGroupsDNRetriever(dn ->
            parentGroupsTree.getOrDefault(dn, new HashSet<>())
    );
}
 
Example #9
Source Project: find   Author: microfocus-idol   File: AutoCreatingEhCacheCacheManager.java    License: MIT License 6 votes vote down vote up
@Override
protected Cache getMissingCache(final String name) {
    final Cache missingCache = super.getMissingCache(name);

    if (missingCache == null) {
        final CacheConfiguration cacheConfiguration = defaults.clone().name(name);

        final String cacheName = getCacheName(name);

        if (cacheExpires.containsKey(cacheName)) {
            cacheConfiguration.setTimeToLiveSeconds(cacheExpires.get(cacheName));
        }

        final net.sf.ehcache.Cache ehcache = new net.sf.ehcache.Cache(cacheConfiguration);
        ehcache.initialise();

        return new EhCacheCache(ehcache);
    } else {
        return missingCache;
    }
}
 
Example #10
Source Project: herd   Author: FINRAOS   File: DaoSpringModuleConfig.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets an EH Cache manager.
 *
 * @return the EH Cache manager.
 */
@Bean(destroyMethod = "shutdown")
public net.sf.ehcache.CacheManager ehCacheManager()
{
    CacheConfiguration cacheConfiguration = new CacheConfiguration();
    cacheConfiguration.setName(HERD_CACHE_NAME);
    cacheConfiguration.setTimeToLiveSeconds(configurationHelper.getProperty(ConfigurationValue.HERD_CACHE_TIME_TO_LIVE_SECONDS, Long.class));
    cacheConfiguration.setTimeToIdleSeconds(configurationHelper.getProperty(ConfigurationValue.HERD_CACHE_TIME_TO_IDLE_SECONDS, Long.class));
    cacheConfiguration.setMaxElementsInMemory(configurationHelper.getProperty(ConfigurationValue.HERD_CACHE_MAX_ELEMENTS_IN_MEMORY, Integer.class));
    cacheConfiguration.setMemoryStoreEvictionPolicy(configurationHelper.getProperty(ConfigurationValue.HERD_CACHE_MEMORY_STORE_EVICTION_POLICY));

    net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
    config.addCache(cacheConfiguration);

    return net.sf.ehcache.CacheManager.create(config);
}
 
Example #11
Source Project: javamelody   Author: javamelody   File: CacheInformations.java    License: Apache License 2.0 6 votes vote down vote up
private String buildConfiguration(Object cache) {
	final StringBuilder sb = new StringBuilder();
	// getCacheConfiguration() et getMaxElementsOnDisk() n'existent pas en ehcache 1.2
	final CacheConfiguration config = ((Ehcache) cache).getCacheConfiguration();
	sb.append("ehcache [maxElementsInMemory = ").append(config.getMaxElementsInMemory());
	final boolean overflowToDisk = config.isOverflowToDisk();
	sb.append(", overflowToDisk = ").append(overflowToDisk);
	if (overflowToDisk) {
		sb.append(", maxElementsOnDisk = ").append(config.getMaxElementsOnDisk());
	}
	final boolean eternal = config.isEternal();
	sb.append(", eternal = ").append(eternal);
	if (!eternal) {
		sb.append(", timeToLiveSeconds = ").append(config.getTimeToLiveSeconds());
		sb.append(", timeToIdleSeconds = ").append(config.getTimeToIdleSeconds());
		sb.append(", memoryStoreEvictionPolicy = ")
				.append(config.getMemoryStoreEvictionPolicy());
	}
	sb.append(", diskPersistent = ").append(config.isDiskPersistent());
	sb.append(']');
	return sb.toString();
}
 
Example #12
Source Project: lutece-core   Author: lutece-platform   File: CacheService.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Read cache config from the file caches.dat
 *
 * @param strCacheName
 *            The cache name
 * @return The config
 */
private CacheConfiguration getCacheConfiguration( String strCacheName )
{
    CacheConfiguration config = new CacheConfiguration( );
    config.setName( strCacheName );
    config.setMaxElementsInMemory( getIntProperty( strCacheName, PROPERTY_MAX_ELEMENTS, _nDefaultMaxElementsInMemory ) );
    config.setEternal( getBooleanProperty( strCacheName, PROPERTY_ETERNAL, _bDefaultEternal ) );
    config.setTimeToIdleSeconds( getLongProperty( strCacheName, PROPERTY_TIME_TO_IDLE, _lDefaultTimeToIdle ) );
    config.setTimeToLiveSeconds( getLongProperty( strCacheName, PROPERTY_TIME_TO_LIVE, _lDefaultTimeToLive ) );
    config.setOverflowToDisk( getBooleanProperty( strCacheName, PROPERTY_OVERFLOW_TO_DISK, _bDefaultOverflowToDisk ) );
    config.setDiskPersistent( getBooleanProperty( strCacheName, PROPERTY_DISK_PERSISTENT, _bDefaultDiskPersistent ) );
    config.setDiskExpiryThreadIntervalSeconds( getLongProperty( strCacheName, PROPERTY_DISK_EXPIRY, _lDefaultDiskExpiry ) );
    config.setMaxElementsOnDisk( getIntProperty( strCacheName, PROPERTY_MAX_ELEMENTS_DISK, _nDefaultMaxElementsOnDisk ) );
    config.setStatistics( getBooleanProperty( strCacheName, PROPERTY_STATISTICS, _bDefaultStatistics ) );

    return config;
}
 
Example #13
Source Project: nextreports-server   Author: nextreports   File: EhCacheFactory.java    License: Apache License 2.0 6 votes vote down vote up
protected void createCache(String name, int expirationTime) {
		synchronized (this.getClass()) {
			cacheManager.addCache(name);

			Ehcache cache = cacheManager.getEhcache(name);
			CacheConfiguration config = cache.getCacheConfiguration();
			config.setEternal(false);
			config.setTimeToLiveSeconds(expirationTime);
//		    config.setTimeToIdleSeconds(60);
//		    config.setMaxElementsInMemory(10000);
//		    config.setMaxElementsOnDisk(1000000);
		    
			BlockingCache blockingCache = new BlockingCache(cache);
			cacheManager.replaceCacheWithDecoratedCache(cache, blockingCache);
		}
	}
 
Example #14
Source Project: spring-analysis-note   Author: Vip-Augus   File: EhCacheCacheManagerTests.java    License: MIT License 5 votes vote down vote up
@Before
public void setup() {
	nativeCacheManager = new CacheManager(new Configuration().name("EhCacheCacheManagerTests")
			.defaultCache(new CacheConfiguration("default", 100)));
	addNativeCache(CACHE_NAME);

	cacheManager = new EhCacheCacheManager(nativeCacheManager);
	cacheManager.setTransactionAware(false);
	cacheManager.afterPropertiesSet();

	transactionalCacheManager = new EhCacheCacheManager(nativeCacheManager);
	transactionalCacheManager.setTransactionAware(true);
	transactionalCacheManager.afterPropertiesSet();
}
 
Example #15
Source Project: spring-analysis-note   Author: Vip-Augus   File: EhCacheCacheTests.java    License: MIT License 5 votes vote down vote up
@Before
public void setup() {
	cacheManager = new CacheManager(new Configuration().name("EhCacheCacheTests")
			.defaultCache(new CacheConfiguration("default", 100)));
	nativeCache = new net.sf.ehcache.Cache(new CacheConfiguration(CACHE_NAME, 100));
	cacheManager.addCache(nativeCache);

	cache = new EhCacheCache(nativeCache);
}
 
Example #16
Source Project: java-technology-stack   Author: codeEngraver   File: EhCacheCacheManagerTests.java    License: MIT License 5 votes vote down vote up
@Before
public void setup() {
	nativeCacheManager = new CacheManager(new Configuration().name("EhCacheCacheManagerTests")
			.defaultCache(new CacheConfiguration("default", 100)));
	addNativeCache(CACHE_NAME);

	cacheManager = new EhCacheCacheManager(nativeCacheManager);
	cacheManager.setTransactionAware(false);
	cacheManager.afterPropertiesSet();

	transactionalCacheManager = new EhCacheCacheManager(nativeCacheManager);
	transactionalCacheManager.setTransactionAware(true);
	transactionalCacheManager.afterPropertiesSet();
}
 
Example #17
Source Project: java-technology-stack   Author: codeEngraver   File: EhCacheCacheTests.java    License: MIT License 5 votes vote down vote up
@Before
public void setup() {
	cacheManager = new CacheManager(new Configuration().name("EhCacheCacheTests")
			.defaultCache(new CacheConfiguration("default", 100)));
	nativeCache = new net.sf.ehcache.Cache(new CacheConfiguration(CACHE_NAME, 100));
	cacheManager.addCache(nativeCache);

	cache = new EhCacheCache(nativeCache);
}
 
Example #18
Source Project: steady   Author: eclipse   File: EHCacheTokenStore.java    License: Apache License 2.0 5 votes vote down vote up
public EHCacheTokenStore(String key, Bus b, URL configFileURL) {
    bus = b;
    if (bus != null) {
        b.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
    }

    cacheManager = EHCacheManagerHolder.getCacheManager(bus, configFileURL);
    // Cannot overflow to disk as SecurityToken Elements can't be serialized
    CacheConfiguration cc = EHCacheManagerHolder.getCacheConfiguration(key, cacheManager);
    cc.overflowToDisk(false); //tokens not writable
    
    Ehcache newCache = new Cache(cc);
    cache = cacheManager.addCacheIfAbsent(newCache);
}
 
Example #19
Source Project: steady   Author: eclipse   File: EHCacheReplayCache.java    License: Apache License 2.0 5 votes vote down vote up
public EHCacheReplayCache(String key, Bus b, URL configFileURL) {
    bus = b;
    if (bus != null) {
        bus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
    }
    cacheManager = EHCacheManagerHolder.getCacheManager(bus, configFileURL);
    
    CacheConfiguration cc = EHCacheManagerHolder.getCacheConfiguration(key, cacheManager);

    Ehcache newCache = new Cache(cc);
    cache = cacheManager.addCacheIfAbsent(newCache);
}
 
Example #20
Source Project: steady   Author: eclipse   File: EHCacheTokenStore.java    License: Apache License 2.0 5 votes vote down vote up
public EHCacheTokenStore(String key, Bus b, URL configFileURL) {
    bus = b;
    if (bus != null) {
        b.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
    }

    cacheManager = EHCacheManagerHolder.getCacheManager(bus, configFileURL);
    // Cannot overflow to disk as SecurityToken Elements can't be serialized
    CacheConfiguration cc = EHCacheManagerHolder.getCacheConfiguration(key, cacheManager);
    cc.overflowToDisk(false); //tokens not writable
    
    Ehcache newCache = new Cache(cc);
    cache = cacheManager.addCacheIfAbsent(newCache);
}
 
Example #21
Source Project: steady   Author: eclipse   File: EHCacheReplayCache.java    License: Apache License 2.0 5 votes vote down vote up
public EHCacheReplayCache(String key, Bus b, URL configFileURL) {
    bus = b;
    if (bus != null) {
        bus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
    }
    cacheManager = EHCacheManagerHolder.getCacheManager(bus, configFileURL);
    
    CacheConfiguration cc = EHCacheManagerHolder.getCacheConfiguration(key, cacheManager);

    Ehcache newCache = new Cache(cc);
    cache = cacheManager.addCacheIfAbsent(newCache);
}
 
Example #22
Source Project: steady   Author: eclipse   File: EHCacheTokenStore.java    License: Apache License 2.0 5 votes vote down vote up
public EHCacheTokenStore(String key, Bus b, URL configFileURL) {
    bus = b;
    if (bus != null) {
        b.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
    }

    cacheManager = EHCacheManagerHolder.getCacheManager(bus, configFileURL);
    // Cannot overflow to disk as SecurityToken Elements can't be serialized
    CacheConfiguration cc = EHCacheManagerHolder.getCacheConfiguration(key, cacheManager);
    cc.overflowToDisk(false); //tokens not writable
    
    Ehcache newCache = new Cache(cc);
    cache = cacheManager.addCacheIfAbsent(newCache);
}
 
Example #23
Source Project: steady   Author: eclipse   File: EHCacheReplayCache.java    License: Apache License 2.0 5 votes vote down vote up
public EHCacheReplayCache(String key, Bus b, URL configFileURL) {
    bus = b;
    if (bus != null) {
        bus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
    }
    cacheManager = EHCacheManagerHolder.getCacheManager(bus, configFileURL);
    
    CacheConfiguration cc = EHCacheManagerHolder.getCacheConfiguration(key, cacheManager);

    Ehcache newCache = new Cache(cc);
    cache = cacheManager.addCacheIfAbsent(newCache);
}
 
Example #24
Source Project: steady   Author: eclipse   File: EHCacheTokenStore.java    License: Apache License 2.0 5 votes vote down vote up
public EHCacheTokenStore(String key, Bus b, URL configFileURL) {
    bus = b;
    if (bus != null) {
        b.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
    }

    cacheManager = EHCacheManagerHolder.getCacheManager(bus, configFileURL);
    // Cannot overflow to disk as SecurityToken Elements can't be serialized
    CacheConfiguration cc = EHCacheManagerHolder.getCacheConfiguration(key, cacheManager);
    cc.overflowToDisk(false); //tokens not writable
    
    Ehcache newCache = new Cache(cc);
    cache = cacheManager.addCacheIfAbsent(newCache);
}
 
Example #25
Source Project: steady   Author: eclipse   File: EHCacheReplayCache.java    License: Apache License 2.0 5 votes vote down vote up
public EHCacheReplayCache(String key, Bus b, URL configFileURL) {
    bus = b;
    if (bus != null) {
        bus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
    }
    cacheManager = EHCacheManagerHolder.getCacheManager(bus, configFileURL);
    
    CacheConfiguration cc = EHCacheManagerHolder.getCacheConfiguration(key, cacheManager);

    Ehcache newCache = new Cache(cc);
    cache = cacheManager.addCacheIfAbsent(newCache);
}
 
Example #26
Source Project: springboot-shiro-cas-mybatis   Author: hsj-xiaokang   File: EhCacheStatistics.java    License: MIT License 5 votes vote down vote up
/**
 * Gets the heap memory capacity of the cache.
 *
 * @return Heap memory capacity.
 */
@Override
public long getCapacity() {
    final CacheConfiguration config = cache.getCacheConfiguration();
    if (useBytes) {
        return config.getMaxBytesLocalDisk();
    }
    return config.getMaxElementsOnDisk();
}
 
Example #27
Source Project: smart-cache   Author: yrain   File: CacheTemplate.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void afterPropertiesSet() throws Exception {
    Cache.ID = key + "." + Dates.newDateStringOfFormatDateTimeSSSNoneSpace();
    Cache.HOST = Utils.getLocalHostIP();
    Cache.CACHE_STORE = key + spliter + "cache" + spliter + "store";
    Cache.CACHE_STORE_SYNC = Cache.CACHE_STORE + spliter + "sync";
    if (this.localEnabled) {
        Configuration configuration = new Configuration();
        configuration.setName(Cache.ID);
        configuration.setMaxBytesLocalHeap(localMaxBytesLocalHeap);
        configuration.setMaxBytesLocalDisk(localMaxBytesLocalDisk);
        // DiskStore
        // 每次启动设置新的文件地址,以避免重启期间一级缓存未同步,以及单机多应用启动造成EhcacheManager重复的问题.
        DiskStoreConfiguration dsc = new DiskStoreConfiguration();
        dsc.setPath(localStoreLocation + Cache.ID);
        configuration.diskStore(dsc);
        // DefaultCache
        CacheConfiguration defaultCacheConfiguration = new CacheConfiguration();
        defaultCacheConfiguration.setEternal(false);
        defaultCacheConfiguration.setOverflowToDisk(true);
        defaultCacheConfiguration.setDiskPersistent(false);
        defaultCacheConfiguration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU);
        defaultCacheConfiguration.setDiskExpiryThreadIntervalSeconds(localDiskExpiryThreadIntervalSeconds);
        // 默认false,使用引用.设置为true,避免外部代码修改了缓存对象.造成EhCache的缓存对象也随之改变
        // 但是设置为true后,将引起element的tti不自动刷新.如果直接新建element去覆盖原值.则本地ttl和远程ttl会产生一定的误差.
        // 因此,使用时放弃手动覆盖方式刷新本地tti,当本地tti过期后,自动从Redis中再获取即可.
        defaultCacheConfiguration.copyOnRead(true);
        defaultCacheConfiguration.copyOnWrite(true);
        defaultCacheConfiguration.setTimeToIdleSeconds(localTimeToIdleSeconds);
        defaultCacheConfiguration.setTimeToLiveSeconds(localTimeToLiveSeconds);
        configuration.setDefaultCacheConfiguration(defaultCacheConfiguration);
        configuration.setDynamicConfig(false);
        configuration.setUpdateCheck(false);
        this.cacheManager = new CacheManager(configuration);
        this.cacheSync = new RedisPubSubSync(this);// 使用Redis Topic发送订阅缓存变更消息
    }
}
 
Example #28
Source Project: cas4.0.x-server-wechat   Author: luotuo   File: EhCacheStatistics.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the heap memory capacity of the cache.
 *
 * @return Heap memory capacity.
 */
@Override
public long getCapacity() {
    final CacheConfiguration config = cache.getCacheConfiguration();
    if (useBytes) {
        return config.getMaxBytesLocalDisk();
    }
    return config.getMaxElementsOnDisk();
}
 
Example #29
Source Project: Mycat2   Author: MyCATApache   File: TestCachePoolPerformance.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static CachePool createEnCachePool() {
	CacheConfiguration cacheConf = new CacheConfiguration();
	cacheConf.setName("testcache");
	cacheConf.maxBytesLocalHeap(400, MemoryUnit.MEGABYTES)
			.timeToIdleSeconds(3600);
	Cache cache = new Cache(cacheConf);
	CacheManager.create().addCache(cache);
	EnchachePool enCachePool = new EnchachePool(cacheConf.getName(),cache,400*10000);
	return enCachePool;
}
 
Example #30
Source Project: dble   Author: actiontech   File: TestCachePoolPerformance.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static CachePool createEnCachePool() {
    CacheConfiguration cacheConf = new CacheConfiguration();
    cacheConf.setName("testcache");
    cacheConf.maxBytesLocalHeap(400, MemoryUnit.MEGABYTES)
            .timeToIdleSeconds(3600);
    Cache cache = new Cache(cacheConf);
    CacheManager.create().addCache(cache);
    EnchachePool enCachePool = new EnchachePool(cacheConf.getName(), cache, 400 * 10000);
    return enCachePool;
}