All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.hmtools.manager.EhCacheManagerDefault Maven / Gradle / Ivy

There is a newer version: 0.0.2.20180312
Show newest version
package top.hmtools.manager;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import net.sf.ehcache.config.CacheConfiguration;
import top.hmtools.EHCMContext;
import top.hmtools.autoConfiguration.EHCMAutoConfiguration;
import top.hmtools.servicer.ehCache2_10.EhCacheServicer;

@Component
public class EhCacheManagerDefault implements IEhCacheManager {
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private EHCMContext ehcmContext;
	
	public EhCacheServicer cacheServicer;

	@Override
	@PostConstruct
	public void init() {
		EHCMAutoConfiguration ehcmAutoConfiguration = ehcmContext.ehcmAutoConfiguration;
		CacheConfiguration cacheConfiguration = new CacheConfiguration(ehcmAutoConfiguration.getCachename(), ehcmAutoConfiguration.getMaxentrieslocalheap());
		cacheConfiguration.maxEntriesLocalDisk(ehcmAutoConfiguration.getMaxentrieslocaldisk());
		cacheConfiguration.eternal(ehcmAutoConfiguration.getEternal());
		cacheConfiguration.diskSpoolBufferSizeMB(ehcmAutoConfiguration.getDiskspoolbuffersizemb());
		cacheConfiguration.timeToIdleSeconds(ehcmAutoConfiguration.getTimetoidleseconds());
		cacheConfiguration.timeToLiveSeconds(ehcmAutoConfiguration.getTimetoliveseconds());
		cacheConfiguration.memoryStoreEvictionPolicy(ehcmAutoConfiguration.getMemorystoreevictionpolicy());
		cacheConfiguration.transactionalMode("off");
		
		cacheServicer = new EhCacheServicer(cacheConfiguration);
		logger.info("ehcache初始化成功:"+cacheConfiguration);
	}

	@Override
	@PreDestroy
	public void destroy() {
		cacheServicer.destory();
	}

	@Override
	public void put(Object key, Object value) {
		cacheServicer.put(key, value);
	}

	@Override
	public void put(Serializable key, Serializable value) {
		cacheServicer.put(key, value);
	}

	@Override
	public Object get(Object key) {
		return cacheServicer.get(key);
	}

	@Override
	public Object get(Serializable key) {
		return cacheServicer.get(key);
	}

	@Override
	public Object replace(Object key, Object value) {
		return cacheServicer.replace(key, value);
	}

	@Override
	public void removeAll() {
		cacheServicer.removeAll();
	}

	@Override
	public void removeAll(Collection keys) {
		cacheServicer.removeAll(keys);
	}

	@Override
	public void remove(Object key) {
		cacheServicer.remove(key);
	}

	@Override
	public void remove(Serializable key) {
		cacheServicer.remove(key);
	}

	@Override
	public List keys() {
		return cacheServicer.keys();
	}

	@Override
	public void refresh() {
		this.destroy();
		this.init();
	}

	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy