添加缓存
1.创建配置文件resource.properties
#内容列表在redis中缓存的key
CONTENT_LIST = CONTENT_LIST
2.修改xml文件
<context:property-placeholder location="classpath:conf/*.properties"/>
3.添加缓存代码
@Value("${CONTENT_LIST}")
private String CONTENT_LIST;
jedisClient.hset(CONTENT_LIST,cid+"", JsonUtils.objectToJson(contents));
4.取出缓存
String hget = jedisClient.hget(CONTENT_LIST, cid + "");
if(StringUtils.isNotBlank(hget)){
List<TbContent> contents = JsonUtils.jsonToList(hget, TbContent.class);
return contents;
}
5.缓存同步
如果对应的数据库增加了一条数据 为了前台进行显示 那就必须要他删除缓存中的数据 即删除对应的id域的内容。
jedisClient.hdel(CONTENT_LIST,content.getCategoryId().toString())