gpt4 book ai didi

java - 创建新项目时的 Spring 缓存

转载 作者:太空宇宙 更新时间:2023-11-04 10:01:06 24 4
gpt4 key购买 nike

我使用项目 ID 来识别缓存数据,如下所示:

@CachePut(value = "users", key = "#p0.id")
@RequestMapping(value = "/user", method = RequestMethod.PUT)
public User updateUser(@RequestBody User user);

创建新项目的函数在创建后返回项目ID。创建新项目后如何将项目保存到缓存中?

@Cacheable(value = "users", key = "???")
@RequestMapping(value = "/user", method = RequestMethod.POST)
public User createUser(@RequestBody User user);

最佳答案

使用@CachePut

@CachePut(value = "users", key = "#result.id"")
@RequestMapping(value = "/user", method = RequestMethod.POST)
public User createUser(@RequestBody User user);

关于java - 创建新项目时的 Spring 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53478344/

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