SpringBoot下自定义缓存
1.依赖导入
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
2.service
模拟从数据库中获取数据并进行相加处理
接口
public interface DemoService {
Integer add(Integer a,Integer b);
}
实现类
定义了内部类,这里简化redis数据缓存,用Map集合代替
@Service
public class DemoServiceImpl implements DemoService {
//自定义缓存机制
//存放请求参数和结果
private Map<Param,Integer> map = new HashMap<>();
//将参数封装到类中
@Data //重写hashcode和equal方法,保