系统中部分热数据,放在数据库查询太慢,所以需要加缓存。
@Autowired
private CacheComponent cacheComponent;
cacheComponent.putObj(CacheConst.CATEGORY_ALL_LIST, resultList, Const.CACHE_ONE_DAY);
更多数据类型、请直接看类里面的方法注释
@AspectCommonCache(value = CacheConst.ADVERT_TYPE, argIndex = {0}, second = 100, arrayClass = AdvertDO.class)
public List<AdvertDO> getActiveAd(Integer adType) throws ServiceException {
QueryWrapper<AdvertDO> wrapper = new QueryWrapper<AdvertDO>()
.eq("status", StatusType.ACTIVE.getCode());
if (adType != null) {
wrapper.eq("type", adType);
}
return advertMapper.selectList(wrapper);
}
使用@AspectCommonCache,会将方法的返回值序列化后作为值,设置到Key为 CacheConst.ADVERT_TYPE + adType 的缓存中。
字段名 | 解释 |
---|---|
value | 缓存Key或缓存Key前缀 |
argIndex | 需要作为Key变量的入参 eg. adType传入为1, key为 CacheConst.ADVERT_TYPE + ":" + adType。中间的0代表第0个 |
second | 表示缓存存活时间 |
arrayClass | 返回值是数组时才需要, 需要反序列化为List泛型才需要传入。否则会自动格式化为 List 是不影响 |