英文:
Creating new Json object in java vs using JSON object from redis
问题
以下是翻译好的内容:
在HttpServletRequest对象中有一些未更改的数据(例如用户的资产详细信息)。我想将这些值设置为API响应。哪种方法是最佳的?如何操作?
- 从HttpServletRequest获取数据并构建用于响应的JSON对象。
- 将JSON响应存储在Redis中,并在API响应中使用这些JSONObject。
英文:
Few unchanged data (for ex. asset details of a user) available in HttpServletRequest object. I want to set these value to a API response. Which one is the best way? How?
- Getting data from HttpServletRequest and construct JSON object for Response
- Store JSON response in Redis and use these JSONObject for API Response
答案1
得分: 0
因为这被标记为[tag:performance]... 选项1会更快,因为它不涉及任何外部调用。
然而,无论Redis有多快,直接从HttpServletRequest
读取总是更快的。
英文:
Since this is tagged [tag:performance]... option 1 will be faster since it doesn't involve any external calls.
However fast Redis might be, reading from HttpServletRequest
directly will always be faster.
专注分享java语言的经验与见解,让所有开发者获益!
评论