在此 cacheManager 中,当使用 getTimeToLive() 超出时间限制时不会自动刷新
private void setCacheInstance() {
cacheManager
.createCache("rateDataCached", CacheConfigurationBuilder
.newCacheConfigurationBuilder(
Integer.class, PostageServicesResultHolder.class,
ResourcePoolsBuilder.heap(100))
.withExpiry(Expirations.timeToLiveExpiration(Duration.of(getTimeToLive(), TimeUnit.MINUTES))).build());
}
private long getTimeToLive() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH.mm");
Float currentTime = Float.parseFloat(sdf.format(cal.getTime()));
return (long) ((24.00-currentTime) * 60);
}