Skip to content

Commit

Permalink
Addressed Sagar's other comment
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Alfonsi <[email protected]>
  • Loading branch information
Peter Alfonsi committed Feb 27, 2024
1 parent d579c51 commit c34c218
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public class EhcacheDiskCache<K, V> implements ICache<K, V> {
private final Serializer<K, byte[]> keySerializer;
private final Serializer<V, byte[]> valueSerializer;

public final static String TIER_DIMENSION_VALUE = "disk";

/**
* Used in computeIfAbsent to synchronize loading of a given key. This is needed as ehcache doesn't provide a
* computeIfAbsent method.
Expand Down Expand Up @@ -154,7 +156,7 @@ private EhcacheDiskCache(Builder<K, V> builder) {
this.valueSerializer);
this.cache = buildCache(Duration.ofMillis(expireAfterAccess.getMillis()), builder);
List<String> dimensionNames = Objects.requireNonNull(builder.dimensionNames, "Dimension names can't be null");
this.stats = new MultiDimensionCacheStats(dimensionNames, CacheStatsDimension.TIER_DIMENSION_VALUE_DISK);
this.stats = new MultiDimensionCacheStats(dimensionNames, TIER_DIMENSION_VALUE);
}

private Cache<ICacheKey, byte[]> buildCache(Duration expireAfterAccess, Builder<K, V> builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ public void testGetStatsByTierName() throws Exception {
for (int i = 0; i < randomKeys; i++) {
ehcacheTest.put(getICacheKey(UUID.randomUUID().toString()), UUID.randomUUID().toString());
}
assertEquals(randomKeys, ehcacheTest.stats().getEntriesByDimensions(List.of(new CacheStatsDimension(CacheStatsDimension.TIER_DIMENSION_NAME, CacheStatsDimension.TIER_DIMENSION_VALUE_DISK))));
assertEquals(0, ehcacheTest.stats().getEntriesByDimensions(List.of(new CacheStatsDimension(CacheStatsDimension.TIER_DIMENSION_NAME, CacheStatsDimension.TIER_DIMENSION_VALUE_ON_HEAP))));
assertEquals(randomKeys, ehcacheTest.stats().getEntriesByDimensions(List.of(new CacheStatsDimension(CacheStatsDimension.TIER_DIMENSION_NAME, EhcacheDiskCache.TIER_DIMENSION_VALUE))));
assertEquals(0, ehcacheTest.stats().getEntriesByDimensions(List.of(new CacheStatsDimension(CacheStatsDimension.TIER_DIMENSION_NAME, "other_tier_value"))));

ehcacheTest.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
public class CacheStatsDimension implements Writeable {
// Values for tier dimensions, that are reused across CacheStats implementations
public static final String TIER_DIMENSION_NAME = "tier";
public static final String TIER_DIMENSION_VALUE_ON_HEAP = "on_heap";
public static final String TIER_DIMENSION_VALUE_DISK = "disk";
public final String dimensionName;
public final String dimensionValue;
public CacheStatsDimension(String dimensionName, String dimensionValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class OpenSearchOnHeapCache<K, V> implements ICache<K, V>, RemovalListene
private final Cache<ICacheKey<K>, V> cache;
private final CacheStats stats;
private final RemovalListener<ICacheKey<K>, V> removalListener;
public static final String TIER_DIMENSION_VALUE = "on_heap";

public OpenSearchOnHeapCache(Builder<K, V> builder) {
CacheBuilder<ICacheKey<K>, V> cacheBuilder = CacheBuilder.<ICacheKey<K>, V>builder()
Expand All @@ -56,7 +57,7 @@ public OpenSearchOnHeapCache(Builder<K, V> builder) {
}
cache = cacheBuilder.build();
List<String> dimensionNames = Objects.requireNonNull(builder.dimensionNames, "Dimension names can't be null");
this.stats = new MultiDimensionCacheStats(dimensionNames, CacheStatsDimension.TIER_DIMENSION_VALUE_ON_HEAP);
this.stats = new MultiDimensionCacheStats(dimensionNames, TIER_DIMENSION_VALUE);
this.removalListener = builder.getRemovalListener();
}

Expand Down

0 comments on commit c34c218

Please sign in to comment.