|
|
package com.yoho.search.common.cache.impls;
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import javax.annotation.PreDestroy;
|
|
|
|
|
|
import net.sf.ehcache.Cache;
|
|
|
import net.sf.ehcache.CacheManager;
|
|
|
import net.sf.ehcache.Element;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -8,18 +15,12 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
import com.yoho.search.common.cache.model.CacheObject;
|
|
|
|
|
|
import net.sf.ehcache.Cache;
|
|
|
import net.sf.ehcache.CacheManager;
|
|
|
import net.sf.ehcache.Element;
|
|
|
|
|
|
@Service("ehCache")
|
|
|
public class EhCache implements CacheInterface {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(EhCache.class);
|
|
|
|
|
|
private static final CacheManager cacheManager = CacheManager.create();
|
|
|
|
|
|
private static final String cacheName = "talent";
|
|
|
private CacheManager manager;
|
|
|
|
|
|
private Cache cache;
|
|
|
|
...
|
...
|
@@ -28,8 +29,20 @@ public class EhCache implements CacheInterface { |
|
|
|
|
|
@PostConstruct
|
|
|
private void init() {
|
|
|
cacheManager.addCache(cacheName);
|
|
|
this.cache = cacheManager.getCache(cacheName);
|
|
|
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("ehcache.xml");
|
|
|
if (inputStream == null) {
|
|
|
logger.error("url is null");
|
|
|
return;
|
|
|
}
|
|
|
this.manager = CacheManager.create(inputStream);
|
|
|
this.cache = manager.getCache("yohosearch");
|
|
|
}
|
|
|
|
|
|
@PreDestroy
|
|
|
private void Destroy() {
|
|
|
if (this.manager != null) {
|
|
|
this.manager.shutdown();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
...
|
...
|
|