admin
2019-04-11 6f3eb63c05041b388a7252bdd42494848f237b3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.yeshi.fanli.util.cache;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Component;
 
import com.google.gson.Gson;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
 
@Component
public class TaoBaoGoodsCacheUtil {
    @Resource
    private RedisManager redisManager;
 
    /**
     * 保存常规的淘宝商品详情(搜索,详情)
     * 
     * @param goods
     */
    public void saveCommonTaoBaoGoodsInfo(TaoBaoGoodsBrief goods) {
        if (goods == null || goods.getAuctionId() == null)
            return;
        String key = "taobao-goods-common-" + goods.getAuctionId();
        // 保存20分钟
        redisManager.cacheCommonString(key, new Gson().toJson(goods), 60 * 20);
    }
 
    /**
     * 获取缓存
     * 
     * @param auctionId
     * @return
     */
    public TaoBaoGoodsBrief getCommonTaoBaoGoodsInfo(long auctionId) {
        String key = "taobao-goods-common-" + auctionId;
        String value = redisManager.getCommonString(key);
        if (!StringUtil.isNullOrEmpty(value)) {
            return new Gson().fromJson(value, TaoBaoGoodsBrief.class);
        } else
            return null;
    }
 
}