苍穹外卖--springCache-@CacheEvict使用
This commit is contained in:
@@ -4,6 +4,7 @@ import com.inmind.entity.User;
|
||||
import com.inmind.mapper.UserMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -35,11 +36,19 @@ public class UserController {
|
||||
return user;
|
||||
}
|
||||
|
||||
/*
|
||||
需求:在根据id删除用户时,redis也删除对应的缓存数据@CacheEvict
|
||||
|
||||
|
||||
*/
|
||||
@CacheEvict(cacheNames = "userCache",key = "#id")//key的生成 userCache::#id
|
||||
@DeleteMapping
|
||||
public void deleteById(Long id){
|
||||
userMapper.deleteById(id);
|
||||
}
|
||||
|
||||
//allEntries = true:以cacheNames开头的所有的键,全部删除(userCache::*)
|
||||
@CacheEvict(cacheNames = "userCache",allEntries = true)//key的生成 userCache::#id
|
||||
@DeleteMapping("/delAll")
|
||||
public void deleteAll(){
|
||||
userMapper.deleteAll();
|
||||
|
||||
Reference in New Issue
Block a user