net.sf.ehcache.config.DiskStoreConfiguration Java Examples

The following examples show how to use net.sf.ehcache.config.DiskStoreConfiguration. 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: WebEhCacheManagerFacotryBean.java    From Lottery with GNU General Public License v2.0 6 votes vote down vote up
public void afterPropertiesSet() throws IOException, CacheException {
	log.info("Initializing EHCache CacheManager");
	Configuration config = null;
	if (this.configLocation != null) {
		config = ConfigurationFactory
				.parseConfiguration(this.configLocation.getInputStream());
		if (this.diskStoreLocation != null) {
			DiskStoreConfiguration dc = new DiskStoreConfiguration();
			dc.setPath(this.diskStoreLocation.getFile().getAbsolutePath());
			try {
				config.addDiskStore(dc);
			} catch (ObjectExistsException e) {
				log.warn("if you want to config distStore in spring,"
						+ " please remove diskStore in config file!", e);
			}
		}
	}
	if (config != null) {
		this.cacheManager = new CacheManager(config);
	} else {
		this.cacheManager = new CacheManager();
	}
	if (this.cacheManagerName != null) {
		this.cacheManager.setName(this.cacheManagerName);
	}
}
 
Example #2
Source File: CacheTemplate.java    From smart-cache with 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 #3
Source File: IbisCacheManager.java    From iaf with Apache License 2.0 5 votes vote down vote up
private IbisCacheManager() {
	Configuration cacheManagerConfig = new Configuration();
	String cacheDir = AppConstants.getInstance().getResolvedProperty(CACHE_DIR_KEY);
	if (StringUtils.isNotEmpty(cacheDir)) {
		log.debug("setting cache directory to ["+cacheDir+"]");
		DiskStoreConfiguration diskStoreConfiguration = new DiskStoreConfiguration();
		diskStoreConfiguration.setPath(cacheDir);
		cacheManagerConfig.addDiskStore(diskStoreConfiguration);
	} 
	CacheConfiguration defaultCacheConfig = new CacheConfiguration();
	cacheManagerConfig.addDefaultCache(defaultCacheConfig);
	cacheManager= new CacheManager(cacheManagerConfig);
}