我使用过 Ehcache 3,而且我是 Ehcache 3 的新手,我有一个缓存管理器,如下所示:
private CacheManager cacheManager;
现在当对象被创建时 cacheManager 被初始化:
public ListPlanImpl() {
System.out.println("constructore being initalized");
System.getProperties().setProperty("java -Dnet.sf.ehcache.use.classic.lru", "true");
cacheManager = CacheManagerBuilder
.newCacheManagerBuilder().build();
cacheManager.init();
}
初始化缓存管理器后,这是我的主类,所有获取和放入缓存的操作都在其中发生。我已将多个数据插入不同的缓存,例如:
@Stateless
public class ListPlanImpl implements CachePlan,ListPlan {
private static final String CACHE_OPERATING_PARAMETER = "cache_key_operating_parameter";
private static final String CACHE_SECURITY_PARAMETER = "cache_security";
private static Cache<String, GenericClassForList> operatingParametersCache;
private static Cache<String, GenericClassForList> securitiesTradingParameterCache;
public void putInCache() throws ExecutionException, InterruptedException {
System.out.println("putting in list");
this.operatingParametersCache = cacheManager
.createCache("cacheOfOperatingParameters", CacheConfigurationBuilder
.newCacheConfigurationBuilder(
String.class, GenericClassForList.class,
ResourcePoolsBuilder.heap(1000000000)).withExpiry(Expirations.timeToLiveExpiration(Duration.of(60000,
TimeUnit.SECONDS))));
operatingParametersCache.put(CACHE_OPERATING_PARAMETER, new GenericClassForList(this.operatingParamService.getOperatingParamDTO()));
this.securitiesTradingParameterCache = cacheManager
.createCache("cacheOfSecurityTrading", CacheConfigurationBuilder
.newCacheConfigurationBuilder(
String.class, GenericClassForList.class,
ResourcePoolsBuilder.heap(1000000000)).withExpiry(Expirations.timeToLiveExpiration(Duration.of(60000,
TimeUnit.SECONDS))));
securitiesTradingParameterCache.put(CACHE_SECURITY_PARAMETER, new GenericClassForList(this.securitiesTradingParamsService.getSecuritiesTradingParamDTO()));
}
}
我想要一个单独的函数,它将返回所有缓存名称和缓存中数据总数的计数,以便我可以在 UI 中显示包含数据的缓存。我搜索了问题,但没有找到解决方案。