Skip to content

Commit

Permalink
Add all cache regions to statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-Frederic Linde committed Feb 19, 2014
1 parent f73627e commit 05e5047
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cachius/src/org/riotfamily/cachius/CacheService.java
Expand Up @@ -40,10 +40,10 @@ public CacheService(DiskStore diskStore) {

public CacheService(DiskStore diskStore, List<Region> regions) {
this.diskStore = diskStore;
this.stats = new CachiusStatistics(this);
for (Region region : regions) {
caches.put(region.getName(), new Cache(region, index));
}
this.stats = new CachiusStatistics(this, caches.keySet());
}

public CachiusStatistics getStatistics() {
Expand Down
23 changes: 17 additions & 6 deletions cachius/src/org/riotfamily/cachius/CachiusStatistics.java
Expand Up @@ -23,11 +23,15 @@
* ***** END LICENSE BLOCK ***** */
package org.riotfamily.cachius;

import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;

public class CachiusStatistics {

private CacheService service;

private Set<String> cacheRegionNames;

private volatile long maxUpdateTime;

Expand All @@ -37,8 +41,9 @@ public class CachiusStatistics {

private AtomicLong misses = new AtomicLong();

protected CachiusStatistics(CacheService service) {
protected CachiusStatistics(CacheService service, Set<String> cacheRegionNames) {
this.service = service;
this.cacheRegionNames = cacheRegionNames;
}

protected void addHit() {
Expand Down Expand Up @@ -82,18 +87,24 @@ public long getMisses() {
return misses.longValue();
}

public int getCapacity() {
return service.getCache(null).getRegion().getCapacity();
public int getCapacity(String region) {
return service.getCache(region).getRegion().getCapacity();
}

public int getSize() {
return service.getCache(null).getSize();
public int getSize(String region) {
return service.getCache(region).getSize();
}

public void invalidateAllItems() {
service.getCache(null).invalidateAll();
for (String region : cacheRegionNames) {
service.getCache(region).invalidateAll();
}
}

public Set<String> getCacheRegionNames() {
return cacheRegionNames;
}

/*public long getAverageOverflowInterval() {
return service.getCache(null).getAverageOverflowInterval();
}
Expand Down
Expand Up @@ -30,28 +30,31 @@

public class CachiusStatisticsDao extends AbstractSimpleStatsDao {

private CachiusStatistics cachius;
private CachiusStatistics cachiusStatistics;

@Required
public void setCacheService(CacheService service) {
this.cachius = service.getStatistics();
cachiusStatistics = service.getStatistics();
}

public CachiusStatistics getCachiusStatistics() {
return cachius;
return cachiusStatistics;
}

@Override
protected void populateStats(Statistics stats) throws Exception {
stats.add("Capacity", cachius.getCapacity());
stats.add("Cached items", cachius.getSize());

for (String region : cachiusStatistics.getCacheRegionNames()) {
stats.add("Capacity [" + region + "]", cachiusStatistics.getCapacity(region));
stats.add("Cached items [" + region + "]", cachiusStatistics.getSize(region));
}
//stats.addMillis("Average overflow interval", cachius.getAverageOverflowInterval());
//stats.add("Max invalidation time [ms]", cachius.getMaxInvalidationTime());

stats.add("Hits", cachius.getHits());
stats.add("Misses", cachius.getMisses());
stats.add("Hits", cachiusStatistics.getHits());
stats.add("Misses", cachiusStatistics.getMisses());

stats.add("Max update time [ms]", cachius.getMaxUpdateTime());
stats.add("Slowest update", cachius.getSlowestUpdate());
stats.add("Max update time [ms]", cachiusStatistics.getMaxUpdateTime());
stats.add("Slowest update", cachiusStatistics.getSlowestUpdate());
}
}

0 comments on commit 05e5047

Please sign in to comment.