【发布时间】:2019-01-07 00:58:55
【问题描述】:
我正在尝试更改以下方法以使用 EhCache 缓存而不是 Guava 缓存,因为从 Spring 5.0 中删除了 Guava 缓存。似乎没有任何关于如何简单地实例化 EhCacheCache 对象并将其传递给 SimpleCacheManager 的在线文档。我如何做到这一点?
@Configuration
@EnableCaching
public class CacheConfig {
@Bean
public CacheManager cacheManager() {
GuavaCache a =
new GuavaCache("a", CacheBuilder.newBuilder().maximumSize(10000)
.expireAfterAccess(24, TimeUnit.HOURS).recordStats().build());
GuavaCache b =
new GuavaCache("b", CacheBuilder.newBuilder().maximumSize(100)
.expireAfterAccess(24, TimeUnit.HOURS).recordStats().build());
GuavaCache c =
new GuavaCache("c", CacheBuilder.newBuilder().maximumSize(100)
.expireAfterAccess(24, TimeUnit.HOURS).recordStats().build());
GuavaCache d =
new GuavaCache("d", CacheBuilder.newBuilder().maximumSize(20)
.expireAfterAccess(24, TimeUnit.HOURS).recordStats().build());
GuavaCache e =
new GuavaCache("e", CacheBuilder.newBuilder().maximumSize(100)
.expireAfterAccess(24, TimeUnit.HOURS).recordStats().build());
GuavaCache f =
new GuavaCache("f", CacheBuilder.newBuilder().maximumSize(10)
.expireAfterAccess(24, TimeUnit.HOURS).recordStats().build());
GuavaCache g =
new GuavaCache("g", CacheBuilder.newBuilder().maximumSize(5000)
.expireAfterAccess(24, TimeUnit.HOURS).recordStats().build());
SimpleCacheManager simpleCacheManager = new SimpleCacheManager();
simpleCacheManager.setCaches(
Arrays.asList(
a,
b,
c,
d,
e,
f,
g
)
);
return simpleCacheManager;
}
}
【问题讨论】:
标签: java spring caching migration ehcache