gpt4 book ai didi

java - 有没有办法将响应实体存储在redis缓存中?

转载 作者:可可西里 更新时间:2023-11-01 11:23:19 26 4
gpt4 key购买 nike

我尝试了以下代码但出现错误 - spring web ResponseEntity 无法序列化。

org.springframework.data.redis.serializer.SerializationException: Cannot serialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [org.springframework.http.ResponseEntity]

尝试了以下代码:

@Override

@Transactional

@Cacheable(value = "mostFollowedSub", key = "{#root.methodName, #offset, #limit}" )
public ResponseEntity<Response> mostFollowedSubCategory(int offset, int limit) {
return subCategoryDao.getMostFollowedSubCategory(offset, limit);
}

最佳答案

ResponseEntity 不是Serializable。更好的方法是在服务/DAO 层进行缓存(在您的情况下是 subCategoryDaogetMostFollowedSubCategory 方法)。

关于java - 有没有办法将响应实体存储在redis缓存中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57393650/

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