-
Notifications
You must be signed in to change notification settings - Fork 4
feat: assignment and bandit caching #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
f913167
3ef59d0
5c29124
e902832
16a1c0f
9b3971c
4bdb444
373ffee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package com.eppo.sdk; | ||
|
||
import cloud.eppo.BaseEppoClient; | ||
import cloud.eppo.api.IAssignmentCache; | ||
import cloud.eppo.cache.ExpiringInMemoryAssignmentCache; | ||
import cloud.eppo.cache.LRUInMemoryAssignmentCache; | ||
import cloud.eppo.logging.AssignmentLogger; | ||
import cloud.eppo.logging.BanditLogger; | ||
import com.eppo.sdk.helpers.AppDetails; | ||
import com.eppo.sdk.helpers.FetchConfigurationsTask; | ||
import java.util.Timer; | ||
import java.util.concurrent.TimeUnit; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
@@ -41,9 +45,23 @@ private EppoClient( | |
String sdkVersion, | ||
AssignmentLogger assignmentLogger, | ||
BanditLogger banditLogger, | ||
boolean isGracefulModel) { | ||
boolean isGracefulModel, | ||
IAssignmentCache assignmentCache, | ||
IAssignmentCache banditAssignmentCache) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
super( | ||
apiKey, host, sdkName, sdkVersion, assignmentLogger, banditLogger, isGracefulModel, false); | ||
apiKey, | ||
host, | ||
sdkName, | ||
sdkVersion, | ||
assignmentLogger, | ||
banditLogger, | ||
null, | ||
isGracefulModel, | ||
false, | ||
true, | ||
null, | ||
assignmentCache, | ||
banditAssignmentCache); | ||
} | ||
|
||
/** Stops the client from polling Eppo for updated flag and bandit configurations */ | ||
|
@@ -63,6 +81,12 @@ public static class Builder { | |
private long pollingIntervalMs = DEFAULT_POLLING_INTERVAL_MS; | ||
private String host = DEFAULT_HOST; | ||
|
||
// Assignment and bandit caching on by default. To disable, call | ||
// `builder.assignmentCache(null).banditAssignmentCache(null);` | ||
private IAssignmentCache assignmentCache = new LRUInMemoryAssignmentCache(100); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How much of this configuration should we surface to devs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the option of providing convenience methods like |
||
private IAssignmentCache banditAssignmentCache = | ||
new ExpiringInMemoryAssignmentCache(10, TimeUnit.MINUTES); | ||
|
||
/** Sets the API Key--created within the eppo application--to use. This is required. */ | ||
public Builder apiKey(String apiKey) { | ||
this.apiKey = apiKey; | ||
|
@@ -125,6 +149,16 @@ public Builder host(String host) { | |
return this; | ||
} | ||
|
||
public Builder assignmentCache(IAssignmentCache assignmentCache) { | ||
this.assignmentCache = assignmentCache; | ||
return this; | ||
} | ||
|
||
public Builder banditAssignmentCache(IAssignmentCache banditAssignmentCache) { | ||
this.banditAssignmentCache = banditAssignmentCache; | ||
return this; | ||
} | ||
|
||
public EppoClient buildAndInit() { | ||
AppDetails appDetails = AppDetails.getInstance(); | ||
String sdkName = appDetails.getName(); | ||
|
@@ -143,7 +177,15 @@ public EppoClient buildAndInit() { | |
|
||
instance = | ||
new EppoClient( | ||
apiKey, sdkName, sdkVersion, host, assignmentLogger, banditLogger, isGracefulMode); | ||
apiKey, | ||
sdkName, | ||
sdkVersion, | ||
host, | ||
assignmentLogger, | ||
banditLogger, | ||
isGracefulMode, | ||
assignmentCache, | ||
banditAssignmentCache); | ||
|
||
// Stop any active polling | ||
stopPolling(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you probably don't need this to be a snapshot version anymore since v3.5.0 has been released, right? same below line 43
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍