gpt4 book ai didi

spring-boot - Spring Boot应用程序中如何在Java中为Redis Cache设置硬编码 key ?

转载 作者:行者123 更新时间:2023-12-03 06:44:57 25 4
gpt4 key购买 nike

我正在尝试使用单个Redis缓存来存储2个Web服务的响应-一个是POST,一个是GET。对于GET服务,没有请求参数可以将Webservice的响应存储在Redis中,当我尝试使用硬编码的Key进行存储时,它给出了以下错误。

null key returned for cache operation (maybe you are using named params on classes without debug info?) Builder[public java.util.Map com.getResponse() throws com.adapter.framework.assetserviceadaptor.exception.ServiceExceptions] caches=[redis-cache] | key='#AssetCache' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'

这就是我试图存储GET服务响应的方式
@Cacheable(value="redis-cache",key ="#AssetCache")
public Map<String, AssetDetailBO> getAssetsResponse() throws COAssetServiceExceptions {
try {
log.info("---- CO_STAGE=[ Caching Service ] ---- ");
return mergingBrokerageAndMutulFund(assetServiceImpl.getAssetResponse());
} catch (ServiceExceptions e) {
log.info("---- CO_STAGE=[ Exception while Calling Assets Adapter For COT ] ---- "
+ e.getErrorMessage());
throw e;
}
}

这就是我存储POST服务响应的方式,这工作正常。
@Cacheable(value="redis-cache",key ="#customerId")
public CustomerDTO retriveCustomerdetails( String customerId, String modelId,
String requestId) throws COException {
CustomerInfo csDTO;
try {
csDTO = csDTOAdapterImpl.
getCustomerDetails(customerId);
} catch (Exception e) {
e.printStackTrace();
}
return csDTO;
}

最佳答案

您可以不使用值和其他属性(例如@Cacheable)来使用@Cacheable("all-students")
例:

@GetMapping("/student/{id}")
@Cacheable(value = "post-single", key = "#id")
public Student findStudentById(@PathVariable String id) {
System.out.println("Searching by ID : " + id);
return studentService.getStudentByID(id);
}

@GetMapping("/students")
@Cacheable("all-students")
public List<Student> getAllStudents() {

List<Student> _ = new ArrayList<>();
_.add(studentService.getStudentByID("1"));
return _;
}

关于spring-boot - Spring Boot应用程序中如何在Java中为Redis Cache设置硬编码 key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61121093/

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