Skip to content

Commit

Permalink
feat: add evictions metrics support for RedissonCache backed by RMapC…
Browse files Browse the repository at this point in the history
…ache

Signed-off-by: Nicola Dardanis <ndardanis@adobe.com>
  • Loading branch information
Nicola Dardanis committed Dec 13, 2022
1 parent bff2966 commit 67407f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Expand Up @@ -46,6 +46,8 @@ public class RedissonCache implements Cache {
private final AtomicLong puts = new AtomicLong();

private final AtomicLong misses = new AtomicLong();

private AtomicLong evictions = new AtomicLong();

public RedissonCache(RMapCache<Object, Object> mapCache, CacheConfig config, boolean allowNullValues) {
this(mapCache, allowNullValues);
Expand Down Expand Up @@ -144,7 +146,8 @@ public ValueWrapper putIfAbsent(Object key, Object value) {

@Override
public void evict(Object key) {
map.fastRemove(key);
long delta = map.fastRemove(key);
addCacheEvictions(delta);
}

@Override
Expand Down Expand Up @@ -238,6 +241,10 @@ long getCacheMisses(){
long getCachePuts() {
return puts.get();
}

long getCacheEvictions() {
return evictions.get();
}

private void addCachePut() {
puts.incrementAndGet();
Expand All @@ -251,4 +258,7 @@ private void addCacheMiss(){
misses.incrementAndGet();
}

private void addCacheEvictions(long delta) {
evictions.addAndGet(delta);
}
}
Expand Up @@ -63,7 +63,7 @@ protected Long missCount() {

@Override
protected Long evictionCount() {
return null;
return cache.getCacheEvictions();
}

@Override
Expand Down

0 comments on commit 67407f0

Please sign in to comment.