gpt4 book ai didi

spring - @CacheEvict 在 SpringBoot 中不起作用

转载 作者:行者123 更新时间:2023-12-05 08:18:55 26 4
gpt4 key购买 nike

@Cacheable(value = "apis", key = "#request")
public Object queryCenterAPI(QCRequest request,HttpHeaders headers) throws JSONException, ParseException {

RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new ToolsResponseHandler());
Response res=new Response();
HashMap<String,String> map=new HashMap<String,String>();
logger.info("No Caching^^^^^^^^^^");
Gson gson = new Gson();
String requestJson = gson.toJson(request);
HttpEntity<String> requestEntity = new HttpEntity<String>(requestJson, headers);
System.out.println("Request Body "+requestEntity);

Object response = null;
try {
response = restTemplate.postForObject(QCUtils.queryURL, requestEntity, Object.class);
logger.info("1st response>"+response);

response = response.toString().replaceAll("\\\\", "");
System.out.println("Final response "+response);

}catch (HttpClientErrorException httpEx) {

logger.info("Error:"+httpEx);
}
return response;

}

@CacheEvict(value = "apis", key = "#request")
public void resetOnRequest(QCRequest request) {
// Intentionally blank
System.out.println("Evict in Progrsss......");

}

缓存工作正常,但我无法使用@CacheEvict 注释。我猜 cacheEvict 方法是在 Cacheable 方法之后立即调用的。在 Cachable 方法(queryCenterAPI)之后不调用 resetOnRequest() 方法。

最佳答案

Cache evict 方法应该从不同的类调用,否则它将不起作用,对于带有 @Cacheable 注释的方法也是如此。

关于spring - @CacheEvict 在 SpringBoot 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48037671/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com