From 867935e8d9a656aeb0f22137b847eb141d6a9350 Mon Sep 17 00:00:00 2001 From: Rahat Ali Date: Mon, 14 Sep 2015 15:17:34 +0500 Subject: [PATCH] cache metrics 112 --- .../org/gluu/oxtrust/service/MetricService.java | 16 +++++++++++++--- server/src/main/resources/ehcache.xml | 7 +++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/gluu/oxtrust/service/MetricService.java b/server/src/main/java/org/gluu/oxtrust/service/MetricService.java index 395bea89e..41373e370 100644 --- a/server/src/main/java/org/gluu/oxtrust/service/MetricService.java +++ b/server/src/main/java/org/gluu/oxtrust/service/MetricService.java @@ -18,6 +18,8 @@ import org.gluu.oxtrust.ldap.service.ApplianceService; import org.gluu.oxtrust.ldap.service.OrganizationService; import org.gluu.oxtrust.model.AuthenticationChartDto; +import org.gluu.oxtrust.model.GluuOrganization; +import org.gluu.oxtrust.util.OxTrustConstants; import org.jboss.seam.Component; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.AutoCreate; @@ -29,6 +31,7 @@ import org.xdi.model.ApplicationType; import org.xdi.model.metric.MetricType; import org.xdi.model.metric.ldap.MetricEntry; +import org.xdi.service.CacheService; /** * Store and retrieve metric @@ -48,7 +51,10 @@ public class MetricService extends org.xdi.service.metric.MetricService { @Logger private Log log; - + + @In + private CacheService cacheService; + @In private ApplianceService applianceService; @@ -60,8 +66,12 @@ public class MetricService extends org.xdi.service.metric.MetricService { public AuthenticationChartDto genereateAuthenticationChartDto(int countDays) { AuthenticationChartDto authenticationChartDto = new AuthenticationChartDto(); - - Map> entries = findAuthenticationMetrics(-countDays); + String key = OxTrustConstants.CACHE_METRICS_KEY; + Map> entries = (Map>) cacheService.get(OxTrustConstants.CACHE_METRICS_NAME, key); + if (entries== null) { + entries = findAuthenticationMetrics(-countDays); + cacheService.put(OxTrustConstants.CACHE_METRICS_NAME, key, entries); + } String []labels = new String[countDays]; Map successStats = calculateStatistics(countDays, entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS)); diff --git a/server/src/main/resources/ehcache.xml b/server/src/main/resources/ehcache.xml index edad07a74..241fde1db 100644 --- a/server/src/main/resources/ehcache.xml +++ b/server/src/main/resources/ehcache.xml @@ -122,4 +122,11 @@ timeToLiveSeconds="60" memoryStoreEvictionPolicy="LRU"/> + \ No newline at end of file