gpt4 book ai didi

redis - 在 spring boot 和 redis 中使用 @Cacheable 与 Spring MongoDB 集成进行缓存

转载 作者:IT王子 更新时间:2023-10-29 06:06:23 25 4
gpt4 key购买 nike

我想知道是否可以在 spring data mongo 存储库上使用 @Cacheable 注释。例如像这样:

public interface UserRepository extends MongoRepository<User, String> {

@Cacheable("byId")
public interface UserRepository extends MongoRepository<User, String> {
User findById(String id);
}
}

我想在接口(interface)类本身上执行此操作,并尽可能避免使用包装类。另外,有没有关于如何使用java配置(不是xml)为redis做缓存配置的示例?

最佳答案

是的,您可以在任何具有 spring 方面的公共(public)方法上使用 Cacheable。您还必须在任何配置类中使用 EnableCaching 和可选的 CacheManager bean。

关于redis - 在 spring boot 和 redis 中使用 @Cacheable 与 Spring MongoDB 集成进行缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39089599/

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