Skip to content

Commit

Permalink
Update the expiration time in OnDemandMuteCache#restart
Browse files Browse the repository at this point in the history
  • Loading branch information
A248 committed Feb 29, 2024
1 parent b680805 commit b75a4fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Predicate;

/**
Expand Down Expand Up @@ -84,8 +83,7 @@ public AlwaysAvailableMuteCache(Configs configs, FactoryOfTheFuture futuresFacto
@Override
public void startup() {
installCache((expirationTime, expirationSemantic) -> {
ConcurrentHashMap<MuteCacheKey, Entry> map = new ConcurrentHashMap<>();
Cache cache = new Cache(map, expirationTime);
Cache cache = new Cache(new ConcurrentHashMap<>(), expirationTime);
cache.startPurgeTask();
this.cache = cache;
});
Expand Down Expand Up @@ -127,18 +125,14 @@ private CentralisedFuture<MuteAndMessage> formatMessage(Punishment mute) {

@Override
public CentralisedFuture<Optional<Punishment>> getCachedMute(UUID uuid, NetworkAddress address) {
return cacheRequestTo(uuid, address, MuteAndMessage::mute);
return cacheRequest(new MuteCacheKey(uuid, address))
.thenApply((opt) -> opt.map(MuteAndMessage::mute));
}

@Override
public CentralisedFuture<Optional<Component>> getCachedMuteMessage(UUID uuid, NetworkAddress address) {
return cacheRequestTo(uuid, address, MuteAndMessage::message);
}

private <T> CentralisedFuture<Optional<T>> cacheRequestTo(UUID uuid, NetworkAddress address,
Function<MuteAndMessage, T> toWhich) {
return cacheRequest(new MuteCacheKey(uuid, address))
.thenApply((muteAndMessage) -> muteAndMessage.map(toWhich));
.thenApply((opt) -> opt.map(MuteAndMessage::message));
}

private CentralisedFuture<Optional<MuteAndMessage>> cacheRequest(MuteCacheKey cacheKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void startup() {

@Override
public void restart() {
cache.synchronous().invalidateAll();
startup();
}

@Override
Expand Down

0 comments on commit b75a4fa

Please sign in to comment.