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