migrate to duration as expiry parameter

This commit is contained in:
Carsten Otto
2021-11-21 20:06:20 +01:00
parent 59d984ec96
commit d4e2120bb6
7 changed files with 39 additions and 55 deletions

View File

@@ -13,6 +13,7 @@ import de.cotto.lndmanagej.model.Pubkey;
import de.cotto.lndmanagej.model.WaitingCloseChannel;
import org.springframework.stereotype.Component;
import java.time.Duration;
import java.util.Collection;
import java.util.Optional;
import java.util.Set;
@@ -22,7 +23,7 @@ import java.util.stream.Stream;
@Component
public class ChannelService {
private static final int CACHE_EXPIRY_MINUTES = 1;
private static final Duration CACHE_EXPIRY = Duration.ofMinutes(1);
private final GrpcChannels grpcChannels;
private final LoadingCache<Object, Set<LocalOpenChannel>> channelsCache;
@@ -33,16 +34,16 @@ public class ChannelService {
public ChannelService(GrpcChannels grpcChannels, GrpcClosedChannels grpcClosedChannels) {
this.grpcChannels = grpcChannels;
channelsCache = new CacheBuilder()
.withExpiryMinutes(CACHE_EXPIRY_MINUTES)
.withExpiry(CACHE_EXPIRY)
.build(grpcChannels::getChannels);
closedChannelsCache = new CacheBuilder()
.withExpiryMinutes(CACHE_EXPIRY_MINUTES)
.withExpiry(CACHE_EXPIRY)
.build(grpcClosedChannels::getClosedChannels);
forceClosingChannelsCache = new CacheBuilder()
.withExpiryMinutes(CACHE_EXPIRY_MINUTES)
.withExpiry(CACHE_EXPIRY)
.build(grpcChannels::getForceClosingChannels);
waitingCloseChannelsCache = new CacheBuilder()
.withExpiryMinutes(CACHE_EXPIRY_MINUTES)
.withExpiry(CACHE_EXPIRY)
.build(grpcChannels::getWaitingCloseChannels);
}

View File

@@ -7,19 +7,21 @@ import de.cotto.lndmanagej.model.Node;
import de.cotto.lndmanagej.model.Pubkey;
import org.springframework.stereotype.Component;
import java.time.Duration;
@Component
public class NodeService {
private static final int MAXIMUM_SIZE = 500;
private static final int ALIAS_CACHE_EXPIRY_MINUTES = 30;
private static final int NODE_CACHE_EXPIRY_SECONDS = 60;
private static final Duration ALIAS_CACHE_EXPIRY = Duration.ofMinutes(30);
private static final Duration NODE_CACHE_EXPIRY = Duration.ofSeconds(60);
private final GrpcNodeInfo grpcNodeInfo;
private final LoadingCache<Pubkey, String> aliasCache = new CacheBuilder()
.withExpiryMinutes(ALIAS_CACHE_EXPIRY_MINUTES)
.withExpiry(ALIAS_CACHE_EXPIRY)
.withMaximumSize(MAXIMUM_SIZE)
.build(this::getAliasWithoutCache);
private final LoadingCache<Pubkey, Node> nodeCache = new CacheBuilder()
.withExpirySeconds(NODE_CACHE_EXPIRY_SECONDS)
.withExpiry(NODE_CACHE_EXPIRY)
.withMaximumSize(MAXIMUM_SIZE)
.build(this::getNodeWithoutCache);

View File

@@ -5,13 +5,15 @@ import de.cotto.lndmanagej.caching.CacheBuilder;
import de.cotto.lndmanagej.grpc.GrpcGetInfo;
import org.springframework.stereotype.Component;
import java.time.Duration;
@Component
public class OwnNodeService {
private static final int CACHE_EXPIRY_SECONDS = 30;
private static final Duration CACHE_EXPIRY = Duration.ofSeconds(30);
private final GrpcGetInfo grpcGetInfo;
private final LoadingCache<Object, Boolean> syncedToChainCache = new CacheBuilder()
.withExpirySeconds(CACHE_EXPIRY_SECONDS)
.withExpiry(CACHE_EXPIRY)
.build(this::isSyncedToChainWithoutCache);
public OwnNodeService(GrpcGetInfo grpcGetInfo) {