@Override public Response<String> apply(CacheResource rsrc, Input input) throws AuthException { if (WEB_SESSIONS.equals(rsrc.getName()) && !self.get().getCapabilities().canMaintainServer()) { throw new AuthException(String.format("only site maintainers can flush %s", WEB_SESSIONS)); } rsrc.getCache().invalidateAll(); return Response.ok(""); }
/** * Method to get the stats about the cache. * * @return */ public String getStats() { StringBuilder stringBuilder = new StringBuilder(); CacheStats cacheStats = cacheResource.getCacheStats().minus(relativeCacheStats); stringBuilder.append( String.format("Total succesful loaded values: %d %n", cacheStats.loadSuccessCount())); stringBuilder.append(String.format("Total requests: %d %n", cacheStats.requestCount())); stringBuilder.append( String.format( "Hits ratio: %d/%d - %.3f %n", cacheStats.hitCount(), cacheStats.missCount(), cacheStats.hitRate())); stringBuilder.append( String.format( "Average time spent loading new values (nanoseconds): %.3f %n", cacheStats.averageLoadPenalty())); stringBuilder.append( String.format("Number of cache evictions: %d %n", cacheStats.evictionCount())); return stringBuilder.toString(); }
@Override public void handleDELETE(CoapExchange exchange) { // reset the cache relativeCacheStats = cacheResource.getCacheStats().minus(relativeCacheStats); exchange.respond(ResponseCode.DELETED); }
/** * Instantiates a new debug resource. * * @param resourceIdentifier the resource identifier * @param cacheResource */ public CacheStatResource(String resourceIdentifier, CacheResource cacheResource) { super(resourceIdentifier); this.cacheResource = cacheResource; relativeCacheStats = cacheResource.getCacheStats(); }