...
|
...
|
@@ -3,10 +3,6 @@ package com.yoho.search.service.cache; |
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
...
|
...
|
@@ -15,18 +11,46 @@ import com.yoho.search.service.cache.caches.EhCache; |
|
|
import com.yoho.search.service.cache.caches.SearchRedis;
|
|
|
import com.yoho.search.service.cache.caches.YohoRedis;
|
|
|
import com.yoho.search.service.cache.model.SearchCache;
|
|
|
import com.yoho.search.service.common.SearchPropertyPlaceholderConfigurer;
|
|
|
import com.yoho.search.service.common.SpringContextHolder;
|
|
|
|
|
|
@Service
|
|
|
public class SearchCacheFactory {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SearchCacheFactory.class);
|
|
|
|
|
|
@Autowired
|
|
|
private SpringContextHolder springContextHolder;
|
|
|
@Autowired
|
|
|
private SearchPropertyPlaceholderConfigurer searchPropertyPlaceholderConfigurer;
|
|
|
// private static final Logger logger =
|
|
|
// LoggerFactory.getLogger(SearchCacheFactory.class);
|
|
|
|
|
|
// @Autowired
|
|
|
// private SpringContextHolder springContextHolder;
|
|
|
// @Autowired
|
|
|
// private SearchPropertyPlaceholderConfigurer
|
|
|
// searchPropertyPlaceholderConfigurer;
|
|
|
|
|
|
// CacheType defaultCacheType = CacheType.YOHO_REDIS;
|
|
|
//
|
|
|
// @PostConstruct
|
|
|
// void init() {
|
|
|
// String searchCacheType = (String)
|
|
|
// searchPropertyPlaceholderConfigurer.getContextProperty("search.cache.type");
|
|
|
// logger.info("searchCacheType is [{}]", searchCacheType);
|
|
|
// if (searchCacheType != null &&
|
|
|
// searchCacheType.equalsIgnoreCase("searchRedis")) {
|
|
|
// defaultCacheType = CacheType.SEARCH_REDIS;
|
|
|
// logger.warn("search.cache.type is searchRedis");
|
|
|
// return;
|
|
|
// }
|
|
|
// if (searchCacheType != null &&
|
|
|
// searchCacheType.equalsIgnoreCase("yohoRedis")) {
|
|
|
// defaultCacheType = CacheType.YOHO_REDIS;
|
|
|
// logger.warn("search.cache.type is yohoRedis");
|
|
|
// return;
|
|
|
// }
|
|
|
// if (searchCacheType != null &&
|
|
|
// searchCacheType.equalsIgnoreCase("ehCache")) {
|
|
|
// defaultCacheType = CacheType.EHCACHE;
|
|
|
// logger.warn("search.cache.type is ehCache");
|
|
|
// return;
|
|
|
// }
|
|
|
// logger.warn("search.cache.type is illegal,use searchRedis as default");
|
|
|
// }
|
|
|
|
|
|
@Autowired
|
|
|
private EhCache ehCache;
|
...
|
...
|
@@ -35,40 +59,16 @@ public class SearchCacheFactory { |
|
|
@Autowired
|
|
|
private YohoRedis yohoRedis;
|
|
|
|
|
|
CacheType defaultCacheType = CacheType.YOHO_REDIS;
|
|
|
|
|
|
@PostConstruct
|
|
|
void init() {
|
|
|
String searchCacheType = (String) searchPropertyPlaceholderConfigurer.getContextProperty("search.cache.type");
|
|
|
logger.info("searchCacheType is [{}]", searchCacheType);
|
|
|
if (searchCacheType != null && searchCacheType.equalsIgnoreCase("searchRedis")) {
|
|
|
defaultCacheType = CacheType.SEARCH_REDIS;
|
|
|
logger.warn("search.cache.type is searchRedis");
|
|
|
return;
|
|
|
}
|
|
|
if (searchCacheType != null && searchCacheType.equalsIgnoreCase("yohoRedis")) {
|
|
|
defaultCacheType = CacheType.YOHO_REDIS;
|
|
|
logger.warn("search.cache.type is yohoRedis");
|
|
|
return;
|
|
|
}
|
|
|
if (searchCacheType != null && searchCacheType.equalsIgnoreCase("ehCache")) {
|
|
|
defaultCacheType = CacheType.EHCACHE;
|
|
|
logger.warn("search.cache.type is ehCache");
|
|
|
return;
|
|
|
}
|
|
|
logger.warn("search.cache.type is illegal,use searchRedis as default");
|
|
|
}
|
|
|
|
|
|
private Map<String, SearchCache> cacheMap = new ConcurrentHashMap<String, SearchCache>();
|
|
|
|
|
|
private CacheInterface getCacheInterface(CacheType cacheType) {
|
|
|
if (cacheType.equals(CacheType.EHCACHE)) {
|
|
|
if (cacheType == CacheType.EHCACHE) {
|
|
|
return ehCache;
|
|
|
}
|
|
|
if (cacheType.equals(CacheType.SEARCH_REDIS)) {
|
|
|
if (cacheType == CacheType.SEARCH_REDIS) {
|
|
|
return searchRedis;
|
|
|
}
|
|
|
if (cacheType.equals(CacheType.YOHO_REDIS)) {
|
|
|
if (cacheType == CacheType.YOHO_REDIS) {
|
|
|
return yohoRedis;
|
|
|
}
|
|
|
return null;
|
...
|
...
|
|