refresh channel caches

This commit is contained in:
Carsten Otto
2021-11-25 20:06:56 +01:00
parent a649067d55
commit c7bc495d16

View File

@@ -24,6 +24,7 @@ import java.util.stream.Stream;
@Component
public class ChannelService {
private static final Duration CACHE_EXPIRY = Duration.ofMinutes(1);
private static final Duration CACHE_REFRESH = Duration.ofSeconds(30);
private final GrpcChannels grpcChannels;
private final LoadingCache<Object, Set<LocalOpenChannel>> localOpenChannelsCache;
@@ -34,15 +35,19 @@ public class ChannelService {
public ChannelService(GrpcChannels grpcChannels, GrpcClosedChannels grpcClosedChannels) {
this.grpcChannels = grpcChannels;
localOpenChannelsCache = new CacheBuilder()
.withRefresh(CACHE_REFRESH)
.withExpiry(CACHE_EXPIRY)
.build(grpcChannels::getChannels);
closedChannelsCache = new CacheBuilder()
.withRefresh(CACHE_REFRESH)
.withExpiry(CACHE_EXPIRY)
.build(grpcClosedChannels::getClosedChannels);
forceClosingChannelsCache = new CacheBuilder()
.withRefresh(CACHE_REFRESH)
.withExpiry(CACHE_EXPIRY)
.build(grpcChannels::getForceClosingChannels);
waitingCloseChannelsCache = new CacheBuilder()
.withRefresh(CACHE_REFRESH)
.withExpiry(CACHE_EXPIRY)
.build(grpcChannels::getWaitingCloseChannels);
}