我正在尝试在我的应用程序中使用 Ehcache 管理器。我想在没有 xml 配置的情况下设置它。我有下一个依赖项:
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.1.1.RELEASE</version>
</dependency>
我有这样的 CacheManager bean:
@Bean
public org.springframework.cache.CacheManager cacheManager() {
org.ehcache.CacheManager mainPageCache = CacheManagerBuilder
.newCacheManagerBuilder()
.withCache("mainPageCache", CacheConfigurationBuilder
.newCacheConfigurationBuilder(
Pageable.class,
Collection.class,
ResourcePoolsBuilder.heap(10))
.withExpiry(ExpiryPolicyBuilder
.timeToLiveExpiration(Duration
.of(10, ChronoUnit.SECONDS))))
.build(true);
// ...
}
是否可以将 Ehcache CacheManager 转换为 Spring CacheManager?我认为应该有类似的东西:return new JCacheCacheManager(/*some code*/);