【问题标题】:Alternate between Spring Boot cache and GemFire在 Spring Boot 缓存和 GemFire 之间交替
【发布时间】:2021-12-24 15:36:38
【问题描述】:

我有一个 Spring Boot 应用程序,它使用 @EnableCaching 类中的 @EnableCaching@Cacheable 为某些方法启用了缓存。这在早期运行良好。

现在我还配置了GemFire缓存来存储其他数据。

带有@Cacheable 注释的旧代码现在正尝试在GemFire 缓存中获取此数据。有没有办法定义何时使用哪个缓存?

我是新手,希望能提供有关在这种情况下应遵循的最佳实践以及可以采取哪些措施来克服这一点的任何意见。

【问题讨论】:

  • 没有 Spring Boot 缓存。 Spring 仅提供了对不同缓存实现的抽象,其中之一是 Gemfire。所以它只不过是一种抽象。
  • 好的,我该如何解决这个问题?较早的缓存数据与GemFire 无法正常工作
  • 您可以定义多个CacheManager 实例(如果您真的想要不同的缓存实现)并使用@Cacheable 上的cacheManager 属性来确定将哪个用于该特定缓存。或者只是仅使用 Gemfire 作为缓存机制。

标签: spring-boot spring-cache gemfire spring-data-gemfire


【解决方案1】:

看看这个:https://docs.spring.io/spring-boot-data-geode-build/current/reference/html5/#geode-caching-provider,特别是这个:https://docs.spring.io/spring-boot-data-geode-build/current/reference/html5/#geode-caching-provider-disable

如果您没有使用 Spring Boot for Apache Geode(SBDG;请参阅 project home 以及 docs)(这也适用于 VMware Tanzu GemFire同样,鉴于 GemFire 是基于 OSS、Apache Geode),那么您绝对应该考虑它。

如果您需要控制哪个缓存用于哪个,例如服务方法,那么你应该阅读更多关于custom cache resolution而不是default cache resolution strategy的信息。

最后,SBDG 向 Spring Boot 的 Caching configuration 致敬,因为 SBDG 本质上是专门为 Apache Geode(和 GemFire)设计和开发的 Spring Boot。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多