Java @Spring Boot中的CacheExit没有删除Redis中的缓存

Java @Spring Boot中的CacheExit没有删除Redis中的缓存,java,spring-boot,caching,redis,Java,Spring Boot,Caching,Redis,我使用@Cacheable注释在Spring Boot中缓存CRUD请求。我使用Redis缓存。缓存已成功完成。当我插入新项目或更新现有项目时,我希望从Redis中逐出或删除多个缓存。为此,我在springboot中使用@cacheexecute标记,如下所示。但是,不会删除缓存。这里有什么问题?(我是Spring环境和Redis的初学者) 应用程序属性 UserController.java 在redis中调用updateUserByID缓存后 127.0.0.1:6379>键* 调用inse

我使用@Cacheable注释在Spring Boot中缓存CRUD请求。我使用Redis缓存。缓存已成功完成。当我插入新项目或更新现有项目时,我希望从Redis中逐出或删除多个缓存。为此,我在springboot中使用@cacheexecute标记,如下所示。但是,不会删除缓存。这里有什么问题?(我是Spring环境和Redis的初学者)

应用程序属性

UserController.java

在redis中调用updateUserByID缓存后

127.0.0.1:6379>键*

调用insertUserupdateUserByID

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/ExampleDB
spring.datasource.username=root
spring.datasource.password=#########
spring.datasource.tomcat.max-wait=20000
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=20
spring.datasource.tomcat.min-idle=15

spring.cache.type=redis
spring.redis.host=127.0.0.1
spring.redis.port=6379

spring.redis.lettuce.pool.max-active=7 
spring.redis.lettuce.pool.max-idle=7
spring.redis.lettuce.pool.min-idle=2
package com.springResearch.redisCaching;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.List;

@RestController(value = "/")
public class UserController {

    @Autowired
    JdbcTemplate jdbcTemplate;

    private static final Logger logger = LogManager.getLogger("Log4J2AsyncLogger");


    @Caching(evict = { @CacheEvict(value = "getallusers"), @CacheEvict(value = "userbyid", key = "#id"), @CacheEvict(value = "getuserbyname")})
    @PostMapping(value = "/insertuser")
    public String insertUser(@RequestParam int id, @RequestParam String name, @RequestParam String address){
        jdbcTemplate.update("insert  into user(userId, username, address) values(?, ?, ?)", id, name, address);
        return "Success";
    }


    @Caching(evict = { @CacheEvict(value = "getallusers"), @CacheEvict(value = "getuserbyid", key = "#id"), @CacheEvict(value = "getuserbyname")})
    @PutMapping(value = "/updateuserbyid")
    public String updateUserByID(@RequestParam int id, @RequestParam String name){

        jdbcTemplate.update(
                "update user set username = ? where userId = ?", name, id
        );
        return "User succesfully updated";
    }


    @Cacheable(value = "getuserbyid", key = "#id")
    @GetMapping(value = "/getuserbyid")
    public List<Map<String, Object>> getUserById(@RequestParam int id){

        logger.info("Data queried from database");
        return this.jdbcTemplate.queryForList(
                "SELECT userId, username, address FROM user WHERE userId = ?", id

        );
    }


    @Cacheable(value = "getuserbyname")
    @GetMapping(value = "/getuserbyname")
    public List<Map<String, Object>> getUserByName(@RequestParam String name){

        logger.info("Data queried from database");
        return this.jdbcTemplate.queryForList(
                "SELECT userId, username, address FROM user WHERE username = ?", name

        );
    }


    @Cacheable(value = "getallusers")
    @GetMapping(value = "/getallusers")
    public List<Map<String, Object>> getAllUsers(){

        List<Map<String, Object>> result =  this.jdbcTemplate.queryForList(
                "SELECT * FROM user"
        );

        logger.info("Table user was queried from database");

        return result;
    }

}
1) "getuserbyid::4"
2) "getuserbyname::sugan"
3) "getallusers::SimpleKey []"
1) "getuserbyid::4"
2) "getuserbyname::sugan"
3) "getallusers::SimpleKey []"