1
1
package com .eppo .sdk ;
2
2
3
3
import cloud .eppo .BaseEppoClient ;
4
+ import cloud .eppo .api .IAssignmentCache ;
5
+ import cloud .eppo .cache .ExpiringInMemoryAssignmentCache ;
6
+ import cloud .eppo .cache .LRUInMemoryAssignmentCache ;
4
7
import cloud .eppo .logging .AssignmentLogger ;
5
8
import cloud .eppo .logging .BanditLogger ;
6
9
import com .eppo .sdk .helpers .AppDetails ;
7
10
import com .eppo .sdk .helpers .FetchConfigurationsTask ;
8
11
import java .util .Timer ;
12
+ import java .util .concurrent .TimeUnit ;
13
+ import org .jetbrains .annotations .Nullable ;
9
14
import org .slf4j .Logger ;
10
15
import org .slf4j .LoggerFactory ;
11
16
@@ -39,9 +44,11 @@ private EppoClient(
39
44
String host ,
40
45
String sdkName ,
41
46
String sdkVersion ,
42
- AssignmentLogger assignmentLogger ,
43
- BanditLogger banditLogger ,
44
- boolean isGracefulModel ) {
47
+ @ Nullable AssignmentLogger assignmentLogger ,
48
+ @ Nullable BanditLogger banditLogger ,
49
+ boolean isGracefulMode ,
50
+ @ Nullable IAssignmentCache assignmentCache ,
51
+ @ Nullable IAssignmentCache banditAssignmentCache ) {
45
52
super (
46
53
apiKey ,
47
54
host ,
@@ -50,10 +57,12 @@ private EppoClient(
50
57
assignmentLogger ,
51
58
banditLogger ,
52
59
null ,
53
- isGracefulModel ,
60
+ isGracefulMode ,
54
61
false ,
55
62
true ,
56
- null );
63
+ null ,
64
+ assignmentCache ,
65
+ banditAssignmentCache );
57
66
}
58
67
59
68
/** Stops the client from polling Eppo for updated flag and bandit configurations */
@@ -73,6 +82,12 @@ public static class Builder {
73
82
private long pollingIntervalMs = DEFAULT_POLLING_INTERVAL_MS ;
74
83
private String host = DEFAULT_HOST ;
75
84
85
+ // Assignment and bandit caching on by default. To disable, call
86
+ // `builder.assignmentCache(null).banditAssignmentCache(null);`
87
+ private IAssignmentCache assignmentCache = new LRUInMemoryAssignmentCache (100 );
88
+ private IAssignmentCache banditAssignmentCache =
89
+ new ExpiringInMemoryAssignmentCache (10 , TimeUnit .MINUTES );
90
+
76
91
/** Sets the API Key--created within the eppo application--to use. This is required. */
77
92
public Builder apiKey (String apiKey ) {
78
93
this .apiKey = apiKey ;
@@ -135,6 +150,16 @@ public Builder host(String host) {
135
150
return this ;
136
151
}
137
152
153
+ public Builder assignmentCache (IAssignmentCache assignmentCache ) {
154
+ this .assignmentCache = assignmentCache ;
155
+ return this ;
156
+ }
157
+
158
+ public Builder banditAssignmentCache (IAssignmentCache banditAssignmentCache ) {
159
+ this .banditAssignmentCache = banditAssignmentCache ;
160
+ return this ;
161
+ }
162
+
138
163
public EppoClient buildAndInit () {
139
164
AppDetails appDetails = AppDetails .getInstance ();
140
165
String sdkName = appDetails .getName ();
@@ -153,7 +178,15 @@ public EppoClient buildAndInit() {
153
178
154
179
instance =
155
180
new EppoClient (
156
- apiKey , sdkName , sdkVersion , host , assignmentLogger , banditLogger , isGracefulMode );
181
+ apiKey ,
182
+ sdkName ,
183
+ sdkVersion ,
184
+ host ,
185
+ assignmentLogger ,
186
+ banditLogger ,
187
+ isGracefulMode ,
188
+ assignmentCache ,
189
+ banditAssignmentCache );
157
190
158
191
// Stop any active polling
159
192
stopPolling ();
0 commit comments