缓存SDK使用教程

使用教程

方法

在E10系统中,缓存使用是通过Spring的@Autowired注解,引入BaseCache缓存对象

package路径:
import com.weaver.common.cache.base.BaseCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

方法说明:
@Autowired
private BaseCache baseCache;//缓存SDK对象
//写入缓存 
//参数说明:moduleKey:缓存模块对象, key:模块内的缓存key主键, value:缓存值, time:缓存失效数据,单位秒
baseCache.set(String moduleKey, String key, Object value, int time);
//读取缓存
//参数说明:moduleKey:缓存模块对象, key:模块内的缓存key主键
baseCache.get(String moduleKey, String key);
//删除缓存
//参数说明:moduleKey:缓存模块对象, key:模块内的缓存key主键
baseCache.del(String moduleKey, String key);

代码案列

package com.weaver.seconddev.broadsync;

import com.weaver.common.cache.base.BaseCache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class CasheTest {

    @Autowired
    private BaseCache baseCache;//缓存对象

    public void Test() {
        //写入缓存(设置缓存失效时间单位 S)
        baseCache.set("dev","testKey","我是缓存的值",60*60);
        //读取缓存
        baseCache.get("dev","testKey");
        //删除缓存
        baseCache.del("dev","testKey");
    }
}