diff --git a/src/main/java/br/ufrgs/inf/prosoft/cache/CacheEvent.java b/src/main/java/br/ufrgs/inf/prosoft/cache/CacheEvent.java
index ea9d275..c96fdc3 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/cache/CacheEvent.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/cache/CacheEvent.java
@@ -14,22 +14,28 @@ public class CacheEvent {
private final long time;
private final String type;
private final int size;
+ private final String identifier;
private CacheEvent(String type) {
this(type, 0);
}
+ private CacheEvent(String type, String identifier) {
+ this(type, identifier, 0);
+ }
+
private CacheEvent(String type, int size) {
- this(System.currentTimeMillis(), type, size);
+ this(type, null, size);
}
- private CacheEvent(long time, String type) {
- this(time, type, 0);
+ private CacheEvent(String type, String identifier, int size) {
+ this(System.currentTimeMillis(), type, identifier, size);
}
- private CacheEvent(long time, String type, int size) {
+ private CacheEvent(long time, String type, String identifier, int size) {
this.time = time;
this.type = type;
+ this.identifier = identifier;
this.size = size;
}
@@ -41,26 +47,50 @@ public class CacheEvent {
return new CacheEvent("ADDITION");
}
+ public static CacheEvent addition(String identifier) {
+ return new CacheEvent("ADDITION", identifier);
+ }
+
public static CacheEvent addition(int size) {
return new CacheEvent("ADDITION", size);
}
+ public static CacheEvent addition(String identifier, int size) {
+ return new CacheEvent("ADDITION", identifier, size);
+ }
+
public static CacheEvent hit() {
return new CacheEvent("HIT");
}
+ public static CacheEvent hit(String identifier) {
+ return new CacheEvent("HIT", identifier);
+ }
+
public static CacheEvent hit(int size) {
return new CacheEvent("HIT", size);
}
+ public static CacheEvent hit(String identifier, int size) {
+ return new CacheEvent("HIT", identifier, size);
+ }
+
public static CacheEvent invalidation() {
return new CacheEvent("INVALIDATION");
}
+ public static CacheEvent invalidation(String identifier) {
+ return new CacheEvent("INVALIDATION", identifier);
+ }
+
public static CacheEvent invalidation(int size) {
return new CacheEvent("INVALIDATION", size);
}
+ public static CacheEvent invalidation(String identifier, int size) {
+ return new CacheEvent("INVALIDATION", identifier, size);
+ }
+
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
@@ -72,6 +102,10 @@ public class CacheEvent {
stringBuilder.append(",");
stringBuilder.append("\"size\":").append(this.size);
}
+ if (this.identifier != null) {
+ stringBuilder.append(",");
+ stringBuilder.append("\"identifier\":").append("\"").append(this.identifier).append("\"");
+ }
stringBuilder.append("}");
return stringBuilder.toString();
}
diff --git a/src/main/java/br/ufrgs/inf/prosoft/cache/CachePerformance.java b/src/main/java/br/ufrgs/inf/prosoft/cache/CachePerformance.java
index f09e44d..31c39f5 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/cache/CachePerformance.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/cache/CachePerformance.java
@@ -67,34 +67,67 @@ public class CachePerformance {
logCacheEvent(CacheEvent.addition());
}
+ public void registerAddition(String identifier) {
+ this.additions++;
+ logCacheEvent(CacheEvent.addition(identifier));
+ }
+
public void registerAddition(int size) {
this.additions++;
this.bytesAdded += size;
logCacheEvent(CacheEvent.addition(size));
}
+ public void registerAddition(String identifier, int size) {
+ this.additions++;
+ this.bytesAdded += size;
+ logCacheEvent(CacheEvent.addition(identifier, size));
+ }
+
public void registerHit() {
this.hits++;
logCacheEvent(CacheEvent.hit());
}
+ public void registerHit(String identifier) {
+ this.hits++;
+ logCacheEvent(CacheEvent.hit(identifier));
+ }
+
public void registerHit(int size) {
this.hits++;
this.bytesHit += size;
logCacheEvent(CacheEvent.hit(size));
}
+ public void registerHit(String identifier, int size) {
+ this.hits++;
+ this.bytesHit += size;
+ logCacheEvent(CacheEvent.hit(identifier, size));
+ }
+
public void registerInvalidation() {
this.invalidations++;
logCacheEvent(CacheEvent.invalidation());
}
+ public void registerInvalidation(String identifier) {
+ this.invalidations++;
+ logCacheEvent(CacheEvent.invalidation(identifier));
+ }
+
public void registerInvalidation(int size) {
this.invalidations++;
this.bytesInvalidated += size;
logCacheEvent(CacheEvent.invalidation(size));
}
+ public void registerInvalidation(String identifier, int size) {
+ this.invalidations++;
+ this.bytesInvalidated += size;
+ logCacheEvent(CacheEvent.invalidation(identifier, size));
+ }
+
public void registerEntry() {
this.maximumSize++;
}
diff --git a/src/main/java/br/ufrgs/inf/prosoft/cache/MultiCache.java b/src/main/java/br/ufrgs/inf/prosoft/cache/MultiCache.java
index ae70731..9c86e56 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/cache/MultiCache.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/cache/MultiCache.java
@@ -58,9 +58,9 @@ public class MultiCache<K, V> implements Cache<K, V> {
invalidate(key);
this.map.put(key, value);
if (CACHE_REGISTER_SIZE) {
- this.cachingPerformance.registerAddition(CachePerformance.calculateObjectSize(value));
+ this.cachingPerformance.registerAddition(String.valueOf(value.hashCode()), CachePerformance.calculateObjectSize(value));
} else {
- this.cachingPerformance.registerAddition();
+ this.cachingPerformance.registerAddition(String.valueOf(value.hashCode()));
}
this.cachingPerformance.registerSize(this.map.size());
}
@@ -72,9 +72,9 @@ public class MultiCache<K, V> implements Cache<K, V> {
this.cachingPerformance.registerMiss();
} else {
if (CACHE_REGISTER_SIZE) {
- this.cachingPerformance.registerHit(CachePerformance.calculateObjectSize(get));
+ this.cachingPerformance.registerHit(String.valueOf(get.hashCode()), CachePerformance.calculateObjectSize(get));
} else {
- this.cachingPerformance.registerHit();
+ this.cachingPerformance.registerHit(String.valueOf(get.hashCode()));
}
}
return get;
@@ -85,9 +85,9 @@ public class MultiCache<K, V> implements Cache<K, V> {
V remove = this.map.remove(key);
if (remove != null) {
if (CACHE_REGISTER_SIZE) {
- this.cachingPerformance.registerInvalidation(CachePerformance.calculateObjectSize(remove));
+ this.cachingPerformance.registerInvalidation(String.valueOf(remove.hashCode()), CachePerformance.calculateObjectSize(remove));
} else {
- this.cachingPerformance.registerInvalidation();
+ this.cachingPerformance.registerInvalidation(String.valueOf(remove.hashCode()));
}
}
}