=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/cache/MemoryAggregationCache.java' --- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/cache/MemoryAggregationCache.java 2010-06-17 22:42:56 +0000 +++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/cache/MemoryAggregationCache.java 2010-07-04 08:53:02 +0000 @@ -32,7 +32,6 @@ import java.util.HashMap; import java.util.Map; -import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodService; @@ -40,7 +39,6 @@ /** * @author Lars Helge Overland - * @version $Id: MemoryAggregationCache.java 4646 2008-02-26 14:54:29Z larshelg $ */ public class MemoryAggregationCache implements AggregationCache @@ -51,14 +49,10 @@ // Cache // ------------------------------------------------------------------------- - private final ThreadLocal latestHierarchyCache = new ThreadLocal(); - - private final ThreadLocal>> hierarchyCache = new ThreadLocal>>(); - - private final ThreadLocal>> childrenCache = new ThreadLocal>>(); - private final ThreadLocal>> intersectingPeriodCache = new ThreadLocal>>(); + private final ThreadLocal>> periodsBetweenDatesCache = new ThreadLocal>>(); + private final ThreadLocal> periodCache = new ThreadLocal>(); private final ThreadLocal> organisationUnitLevelCache = new ThreadLocal>(); @@ -109,6 +103,30 @@ return periods; } + public Collection getPeriodsBetweenDates( final Date startDate, final Date endDate ) + { + final String key = startDate.toString() + SEPARATOR + endDate.toString(); + + Map> cache = periodsBetweenDatesCache.get(); + + Collection periods = null; + + if ( cache != null && ( periods = cache.get( key ) ) != null ) + { + return periods; + } + + periods = ConversionUtils.getIdentifiers( Period.class, periodService.getPeriodsBetweenDates( startDate, endDate ) ); + + cache = ( cache == null ) ? new HashMap>() : cache; + + cache.put( key, periods ); + + periodsBetweenDatesCache.set( cache ); + + return periods; + } + public Period getPeriod( final int id ) { final String key = String.valueOf( id ); @@ -159,10 +177,9 @@ public void clearCache() { - latestHierarchyCache.remove(); - hierarchyCache.remove(); - childrenCache.remove(); intersectingPeriodCache.remove(); + periodsBetweenDatesCache.remove(); periodCache.remove(); + organisationUnitLevelCache.remove(); } }