|
3 | 3 | import cloud.eppo.cache.AssignmentCacheEntry;
|
4 | 4 | import cloud.eppo.cache.AssignmentCacheKey;
|
5 | 5 | import java.util.Map;
|
| 6 | +import org.jetbrains.annotations.NotNull; |
| 7 | +import org.jetbrains.annotations.Nullable; |
6 | 8 |
|
7 | 9 | /**
|
8 | 10 | * {@link IAssignmentCache} implementation which takes a map to use as the underlying storage
|
9 | 11 | * mechanism.
|
10 | 12 | */
|
11 | 13 | public abstract class AbstractAssignmentCache implements IAssignmentCache {
|
12 |
| - protected final Map<String, String> delegate; |
13 | 14 |
|
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) { |
15 | 25 | this.delegate = delegate;
|
16 | 26 | }
|
17 | 27 |
|
| 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 | + |
18 | 44 | @Override
|
19 | 45 | public boolean hasEntry(AssignmentCacheEntry entry) {
|
20 | 46 | String serializedEntry = get(entry.getKey());
|
|
0 commit comments