1

我有一个 Spring Boot Web 应用程序并使用带有 redis 存储的 spring 会话。Web 请求有时需要缓存它们的响应(以避免不必要的数据库旅行),我计划使用 Caffeine。
然而,似乎 Redis 接管了(只要我包含 gradle 依赖项)作为缓存实现,因为我为咖啡因设置的所有 TTL 都被忽略了。

在 Spring Boot 应用程序中使用超过 1 个缓存提供程序是否可能/值得推荐?我可以尝试将 Redis 用于所有缓存,只是担心它会影响 Spring Boot 附带的会话实现(我没有配置任何东西,只是使用了@EnableRedisHttpSession)。

我很感激对此的任何建议。

4

1 回答 1

2

您可以使用单独的缓存管理器@Cacheable

@RequestMapping(value = "/hello/{name}", method = RequestMethod.GET)
@Cacheable(key = "#name", cacheManager = "caffeineCacheManager")
public String greeet(@PathVariable String name) {
    return "Hello " + name;
}

你唯一需要的就是让你的缓存管理器作为一个命名的bean:

@Bean
@Qualifier("caffeineCacheManager")
AbstractCacheManager caffeineCacheManager() {
    return new CaffeineCacheManager();
}
于 2017-06-16T10:49:55.817 回答