Skip to content

Commit 1a23dbb

Browse files
authored
feat: extract minimal assignment cache map (#55)
* minimal map * comments and version (minor bump for a new api)
1 parent 19d4eb3 commit 1a23dbb

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

build.gradle

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = 'cloud.eppo'
9-
version = '3.4.2-SNAPSHOT'
9+
version = '3.5.0-SNAPSHOT'
1010
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
1111

1212
java {
@@ -51,18 +51,14 @@ spotless {
5151
ratchetFrom 'origin/main'
5252

5353
format 'misc', {
54-
// define the files to apply `misc` to
5554
target '*.gradle', '.gitattributes', '.gitignore'
5655

57-
// define the steps to apply to those files
5856
trimTrailingWhitespace()
59-
indentWithSpaces(2) // or spaces. Takes an integer argument if you don't like 4
57+
indentWithSpaces(2)
6058
endWithNewline()
6159
}
6260
java {
63-
// apply a specific flavor of google-java-format
6461
googleJavaFormat('1.7')
65-
// fix formatting of type annotations
6662
formatAnnotations()
6763
}
6864
}

src/main/java/cloud/eppo/api/AbstractAssignmentCache.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,44 @@
33
import cloud.eppo.cache.AssignmentCacheEntry;
44
import cloud.eppo.cache.AssignmentCacheKey;
55
import java.util.Map;
6+
import org.jetbrains.annotations.NotNull;
7+
import org.jetbrains.annotations.Nullable;
68

79
/**
810
* {@link IAssignmentCache} implementation which takes a map to use as the underlying storage
911
* mechanism.
1012
*/
1113
public abstract class AbstractAssignmentCache implements IAssignmentCache {
12-
protected final Map<String, String> delegate;
1314

14-
protected AbstractAssignmentCache(final Map<String, String> delegate) {
15+
/** Minimal "map" implementation required to store cached assignment data. */
16+
public interface CacheDelegate {
17+
void put(String cacheKey, @NotNull String serializedEntry);
18+
19+
@Nullable String get(String cacheKey);
20+
}
21+
22+
protected final CacheDelegate delegate;
23+
24+
protected AbstractAssignmentCache(final CacheDelegate delegate) {
1525
this.delegate = delegate;
1626
}
1727

28+
protected AbstractAssignmentCache(final Map<String, String> delegate) {
29+
this(
30+
new CacheDelegate() {
31+
32+
@Override
33+
public void put(String cacheKey, @NotNull String serializedEntry) {
34+
delegate.put(cacheKey, serializedEntry);
35+
}
36+
37+
@Nullable @Override
38+
public String get(String cacheKey) {
39+
return delegate.get(cacheKey);
40+
}
41+
});
42+
}
43+
1844
@Override
1945
public boolean hasEntry(AssignmentCacheEntry entry) {
2046
String serializedEntry = get(entry.getKey());

0 commit comments

Comments
 (0)