Skip to content

Commit

Permalink
Use constant for cache eviction duration
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenreichardt committed Apr 24, 2024
1 parent df4ebed commit bc6c6aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@
import org.neo4j.gds.core.concurrency.ExecutorServiceUtil;
import org.neo4j.gds.core.utils.ClockService;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.LongUnaryOperator;
import java.util.stream.Stream;

public class EphemeralResultStore implements ResultStore {

private static final String NO_PROPERTY_KEY = "";
private static final List<String> NO_PROPERTIES_LIST = List.of(NO_PROPERTY_KEY);
static final Duration CACHE_EVICTION_DURATION = Duration.of(10, ChronoUnit.MINUTES);

private final Cache<NodeKey, NodePropertyValues> nodeProperties;
private final Cache<String, NodeLabelEntry> nodeIdsByLabel;
Expand Down Expand Up @@ -164,7 +166,7 @@ public boolean hasRelationshipStream(String relationshipType, List<String> prope

private static <K, V> Cache<K, V> createCache(ScheduledExecutorService singleThreadScheduler) {
return Caffeine.newBuilder()
.expireAfterAccess(10, TimeUnit.MINUTES)
.expireAfterAccess(CACHE_EVICTION_DURATION)
.ticker(new ClockServiceWrappingTicker())
.executor(singleThreadScheduler)
.scheduler(Scheduler.forScheduledExecutorService(singleThreadScheduler))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.neo4j.time.FakeClock;

import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.LongUnaryOperator;
import java.util.stream.Stream;

Expand Down Expand Up @@ -83,7 +82,7 @@ void shouldEvictNodePropertyEntryAfter10Minutes() throws InterruptedException {

assertThat(resultStore.getNodePropertyValues(List.of("A"), "prop")).isNotNull();

clock.forward(11, TimeUnit.MINUTES);
clock.forward(EphemeralResultStore.CACHE_EVICTION_DURATION.plusMinutes(1));
// make some room for the cache eviction thread to trigger a cleanup
Thread.sleep(100);

Expand Down Expand Up @@ -130,7 +129,7 @@ void shouldEvictNodeLabelEntryAfter10Minutes() throws InterruptedException {

assertThat(resultStore.hasNodeLabel("Label")).isTrue();

clock.forward(11, TimeUnit.MINUTES);
clock.forward(EphemeralResultStore.CACHE_EVICTION_DURATION.plusMinutes(1));
// make some room for the cache eviction thread to trigger a cleanup
Thread.sleep(100);

Expand Down Expand Up @@ -180,7 +179,7 @@ void shouldEvictGraphBasedRelationshipsWithoutPropertyAfter10Minutes() throws In

assertThat(resultStore.hasRelationship("Type")).isTrue();

clock.forward(11, TimeUnit.MINUTES);
clock.forward(EphemeralResultStore.CACHE_EVICTION_DURATION.plusMinutes(1));
// make some room for the cache eviction thread to trigger a cleanup
Thread.sleep(100);

Expand Down Expand Up @@ -231,7 +230,7 @@ void shouldEvictGraphBasedRelationshipsWithPropertyAfter10Minutes() throws Inter
assertThat(resultStore.hasRelationship("Type", List.of("prop"))).isTrue();


clock.forward(11, TimeUnit.MINUTES);
clock.forward(EphemeralResultStore.CACHE_EVICTION_DURATION.plusMinutes(1));
// make some room for the cache eviction thread to trigger a cleanup
Thread.sleep(100);

Expand Down Expand Up @@ -282,7 +281,7 @@ void shouldEvictStreamBasedRelationshipsAfter10Minutes() throws InterruptedExcep

assertThat(resultStore.hasRelationshipStream("Type", List.of("foo"))).isTrue();

clock.forward(11, TimeUnit.MINUTES);
clock.forward(EphemeralResultStore.CACHE_EVICTION_DURATION.plusMinutes(1));
// make some room for the cache eviction thread to trigger a cleanup
Thread.sleep(100);

Expand Down

0 comments on commit bc6c6aa

Please sign in to comment.