目录
(1)数据存储在内存中,数据查询速度快。可以分摊数据库压力。

(2)什么样的数据适合放入缓存。
查询频率比较高,修改频率比较低。
安全系数低的数据
(3)使用redis作为缓存
- package com.wzl.qy151redisspringboot.service;
-
- import com.wzl.qy151redisspringboot.dao.DeptMapper;
- import com.wzl.qy151redisspringboot.entity.Dept;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.data.redis.core.ValueOperations;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
-
- import java.util.concurrent.TimeUnit;
-
-
- @Service
- public class DeptService {
-
- @Autowired
- private DeptMapper deptMapper;
-
- @Autowired
- private RedisTemplate redisTemplate;
-
- //业务代码
- publ