Skip to content

Commit

Permalink
增加了菜单缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
sdksdk0 committed Nov 3, 2016
1 parent 1e51fc7 commit 3a47e9b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Wed Oct 26 20:59:40 CST 2016
#Thu Nov 03 14:15:49 CST 2016
version=0.0.1-SNAPSHOT
groupId=cn.tf.taotao
m2e.projectName=taotao-manager-web
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Thu Oct 27 10:48:43 CST 2016
#Thu Nov 03 14:15:50 CST 2016
version=0.0.1-SNAPSHOT
groupId=cn.tf.taotao
m2e.projectName=taotao-portal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ public class ItemCatServiceImpl implements ItemCatService{
@Autowired
private JedisClient jedisClient;

//分类列表
@Value("${REDIS_CAT_ITEM1}")
private String REDIS_CAT_ITEM1;


@Value("${REDIS_CAT_ITEM2")
private String REDIS_CAT_ITEM2;
@Value("${INDEX_CATEGORY_REDIS_KEY}")
private String INDEX_CATEGORY_REDIS_KEY;


//过期时间设置
Expand All @@ -47,6 +42,22 @@ public class ItemCatServiceImpl implements ItemCatService{
@Override
public CatResult getItemCatList() {
CatResult catResult=new CatResult();


try {
// 添加redis业务
// 1.先在redis中查询 ,如果有值,直接返回
String resultString = jedisClient.get(INDEX_CATEGORY_REDIS_KEY);
if (!StringUtils.isBlank(resultString)) {
catResult.setData(JsonUtils.jsonToList(resultString,
CatNode.class));
return catResult;
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}

//查询分类列表
catResult.setData(getCatList(0));
return catResult;
Expand Down Expand Up @@ -90,6 +101,13 @@ private List<?> getCatList(long parentId){
resultList.add("/products/"+tbItemCat.getId()+".html|"+tbItemCat.getName());
}
}

// 3. 查询完mysql后,将查询结果存入到redis中
jedisClient.set(INDEX_CATEGORY_REDIS_KEY,
JsonUtils.objectToJson(resultList));

jedisClient.expire(INDEX_CATEGORY_REDIS_KEY,
REDIS_ITEM_EXPIRE);

return resultList;
}
Expand Down
4 changes: 1 addition & 3 deletions taotao-rest/src/main/resources/resource/resource.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ REDIS_ITEM_EXPIRE=86400


#列表
REDIS_CAT_ITEM1=REDIS_CAT_ITEM1

REDIS_CAT_ITEM2=REDIS_CAT_ITEM2
INDEX_CATEGORY_REDIS_KEY=INDEX_CATEGORY_REDIS_KEY
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Wed Oct 26 20:59:42 CST 2016
#Thu Nov 03 14:19:14 CST 2016
version=0.0.1-SNAPSHOT
groupId=cn.tf.taotao
m2e.projectName=taotao-rest
Expand Down

0 comments on commit 3a47e9b

Please sign in to comment.