Spring RedisTemplate操作-注解缓存操作(11)

@Service
@CacheConfig(cacheNames="user")
public class RedisAn {
    
    
    
    public Map<String, User> map = new HashMap<>();
    
    public void insert(User user){
        map.put(user.getId(), user);
    }
    
    @Cacheable(key = "'id_'+#id")
    public User get(String id){
        System.out.println("get被调用了");
        return map.get(id);
    }
    
    @CacheEvict(key = "'id_'+#id") 
    public User del(String id){
        return map.remove(id);
    }
    
    @CacheEvict(allEntries=true) 
    public void delAll(){
        
    }
    
    public Map<String, User> getMap() {
        return map;
    }

    public void setMap(Map<String, User> map) {
        this.map = map;
    }
原文地址:https://www.cnblogs.com/aoeiuv/p/6761898.html