Authored by hugufei

AbstractCacheComponent支持针对特殊param值缓存

... ... @@ -21,7 +21,7 @@ public abstract class AbstractCacheComponent<T> {
public T queryWithCache(ParamQueryFilter paramQueryFilter, Map<String, String> paramMap) throws Exception {
//1、生成RedisKeyBuilder
RedisKeyBuilder redisKeyBuilder = this.genRedisKeyBuilder(paramQueryFilter);
RedisKeyBuilder redisKeyBuilder = this.genRedisKeyBuilder(paramQueryFilter,paramMap);
if (redisKeyBuilder == null) {
return null;
}
... ... @@ -96,10 +96,19 @@ public abstract class AbstractCacheComponent<T> {
return JSON.parseObject(redisValue, type);
}
protected abstract RedisKeyBuilder genRedisKeyBuilder(ParamQueryFilter paramQueryFilter);
protected abstract int cacheTimeInMinute();
protected abstract String cacheSceneKey();
protected RedisKeyBuilder genRedisKeyBuilder(ParamQueryFilter paramQueryFilter,Map<String,String> paramMap){
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance();
redisKeyBuilder.appendFixed("YOHOSEARCH").appendFixed(":");//前缀
redisKeyBuilder.appendFixed(cacheSceneKey()).appendFixed(":");//场景
redisKeyBuilder.appendFixed(cacheTimeInMinute()).appendFixed(":");//缓存时间
redisKeyBuilder.appendVar(paramQueryFilter.getParamMd5Key());//报文
return redisKeyBuilder;
}
protected boolean useEhcache() {
return false;
}
... ...
package com.yoho.search.service.recall.beans.persional;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.cache.CacheTimeConstants;
... ... @@ -50,13 +49,13 @@ public class CachePersionalFactorComponent extends AbstractCacheComponent<PagePe
}
@Override
protected RedisKeyBuilder genRedisKeyBuilder(ParamQueryFilter paramQueryFilter) {
return RedisKeyBuilder.newInstance().appendFixed("YOHOSEARCH:").appendFixed("PAGE_FACTORS_NEW:").appendVar(paramQueryFilter.getParamMd5Key());
protected int cacheTimeInMinute() {
return CacheTimeConstants.PAGE_PERSIONAL_FACTOR;
}
@Override
protected int cacheTimeInMinute() {
return CacheTimeConstants.PAGE_PERSIONAL_FACTOR;
protected String cacheSceneKey() {
return "PERSIONAL_FACTOR";
}
@Override
... ...
... ... @@ -55,13 +55,13 @@ public class ActivityShopBrandListService extends AbstractCacheComponent<List<Ac
}
@Override
protected RedisKeyBuilder genRedisKeyBuilder(ParamQueryFilter paramQueryFilter) {
return RedisKeyBuilder.newInstance().appendFixed("YOHOSEARCH:").appendFixed("ACTIVITY_SHOP_BRANDS:").appendVar(paramQueryFilter.getParamMd5Key());
protected int cacheTimeInMinute() {
return CacheTimeConstants.CACHE_60_MINUTE;
}
@Override
protected int cacheTimeInMinute() {
return CacheTimeConstants.CACHE_60_MINUTE;
protected String cacheSceneKey() {
return "ACTIVITY_SHOP_BRANDS";
}
@Override
... ...
... ... @@ -65,13 +65,13 @@ public class DiscountService extends AbstractCacheComponent<JSONObject> implemen
}
@Override
protected RedisKeyBuilder genRedisKeyBuilder(ParamQueryFilter paramQueryFilter) {
return RedisKeyBuilder.newInstance().appendFixed("YOHOSEARCH:").appendFixed("DISCOUNT:").appendVar(paramQueryFilter.getParamMd5Key());
protected int cacheTimeInMinute() {
return CacheTimeConstants.CACHE_15_MINUTE;
}
@Override
protected int cacheTimeInMinute() {
return CacheTimeConstants.CACHE_15_MINUTE;
protected String cacheSceneKey() {
return "DISCOUNT";
}
@Override
... ...
... ... @@ -2,7 +2,6 @@ package com.yoho.search.service.scene.shopbrand;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.cache.beans.AbstractCacheComponent;
import com.yoho.search.common.SearchRequestParams;
... ... @@ -53,8 +52,8 @@ public class AggBrandService extends AbstractCacheComponent<JSONArray> {
}
@Override
protected RedisKeyBuilder genRedisKeyBuilder(ParamQueryFilter paramQueryFilter) {
return RedisKeyBuilder.newInstance().appendFixed("YOHOSEARCH:").appendFixed("AGG_BRAND_LIST:").appendVar(paramQueryFilter.getParamMd5Key());
protected String cacheSceneKey() {
return "AGG_BRAND_LIST";
}
@Override
... ...
... ... @@ -84,13 +84,12 @@ public class RecommendBrandService extends AbstractCacheComponent<JSONArray> {
return new JSONArray();
}
// 4、生成结果
JSONArray brandJSONArray = recommendBrandResult.getJSONArray(recommendBrandAgg.aggName());
return brandJSONArray;
return recommendBrandResult.getJSONArray(recommendBrandAgg.aggName());
}
@Override
protected RedisKeyBuilder genRedisKeyBuilder(ParamQueryFilter paramQueryFilter) {
return RedisKeyBuilder.newInstance().appendFixed("YOHOSEARCH:").appendFixed("RECOMMEND_BRAND:").appendVar(paramQueryFilter.getParamMd5Key());
protected String cacheSceneKey() {
return "RECOMMEND_BRAND";
}
@Override
... ... @@ -98,4 +97,12 @@ public class RecommendBrandService extends AbstractCacheComponent<JSONArray> {
return CacheTimeConstants.CACHE_15_MINUTE;
}
@Override
protected RedisKeyBuilder genRedisKeyBuilder(ParamQueryFilter paramQueryFilter, Map<String,String> paramMap){
RedisKeyBuilder redisKeyBuilder = super.genRedisKeyBuilder(paramQueryFilter,paramMap);
int recommendBrandCount = MapUtils.getIntValue(paramMap, SearchRequestParams.PARAM_SEARCH_VIEWNUM, 8);
redisKeyBuilder.appendFixed(":").appendVar(recommendBrandCount);
return redisKeyBuilder;
}
}
... ...