Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Add field in MemoryPolicy to control the duration of the Inflight Debouncer #374

Open
wants to merge 1 commit into
base: feature/rx2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static <Key, Value> Cache<Key, Value> createBaseInFlighter(MemoryPolicy
long expireAfterToSeconds = memoryPolicy == null ? StoreDefaults.getCacheTTLTimeUnit()
.toSeconds(StoreDefaults.getCacheTTL())
: memoryPolicy.getExpireAfterTimeUnit().toSeconds(memoryPolicy.getExpireAfterWrite());
long maximumInFlightRequestsDuration = TimeUnit.MINUTES.toSeconds(1);
long maximumInFlightRequestsDuration = memoryPolicy == null ? TimeUnit.MINUTES.toSeconds(1) : memoryPolicy.getMaximumInFlightRequestsDurationInSeconds();

if (expireAfterToSeconds > maximumInFlightRequestsDuration) {
return CacheBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ public class MemoryPolicy {
private final long expireAfterAccess;
private final TimeUnit expireAfterTimeUnit;
private final long maxSize;
private final long maximumInFlightRequestsDurationInSeconds;

MemoryPolicy(long expireAfterWrite, long expireAfterAccess, TimeUnit expireAfterTimeUnit, long maxSize) {
MemoryPolicy(long expireAfterWrite, long expireAfterAccess, TimeUnit expireAfterTimeUnit, long maxSize, long maximumInFlightRequestsDurationInSeconds) {
this.expireAfterWrite = expireAfterWrite;
this.expireAfterAccess = expireAfterAccess;
this.expireAfterTimeUnit = expireAfterTimeUnit;
this.maxSize = maxSize;
this.maximumInFlightRequestsDurationInSeconds = maximumInFlightRequestsDurationInSeconds;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think allowing a timeunit + duration would be more consistent with rest of api

}

public static MemoryPolicyBuilder builder() {
Expand Down Expand Up @@ -63,6 +65,10 @@ public long getMaxSize() {
return maxSize;
}

public long getMaximumInFlightRequestsDurationInSeconds() {
return maximumInFlightRequestsDurationInSeconds;
}

/**
* @deprecated Use {@link MemoryPolicy#isDefaultWritePolicy()} or {@link MemoryPolicy#isDefaultAccessPolicy()}.
*/
Expand Down Expand Up @@ -100,6 +106,7 @@ public static class MemoryPolicyBuilder {
private long expireAfterAccess = DEFAULT_POLICY;
private TimeUnit expireAfterTimeUnit = TimeUnit.SECONDS;
private long maxSize = -1;
private long maximumInFlightRequestsFurationInSeconds = 60;

/**
* @deprecated Use {@link MemoryPolicyBuilder#setExpireAfterWrite(long)} or
Expand Down Expand Up @@ -136,8 +143,13 @@ public MemoryPolicyBuilder setMemorySize(long maxSize) {
return this;
}

public MemoryPolicyBuilder setMaximumInFlightRequestsDurationInSeconds(long maximumInFlightRequestsDurationInSeconds) {
this.maximumInFlightRequestsFurationInSeconds = maximumInFlightRequestsDurationInSeconds;
return this;
}

public MemoryPolicy build() {
return new MemoryPolicy(expireAfterWrite, expireAfterAccess, expireAfterTimeUnit, maxSize);
return new MemoryPolicy(expireAfterWrite, expireAfterAccess, expireAfterTimeUnit, maxSize, maximumInFlightRequestsFurationInSeconds);
}
}
}