dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #32356
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16514: add caching to PeriodType
------------------------------------------------------------
revno: 16514
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-08-26 15:03:20 +0700
message:
add caching to PeriodType
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/TimeUnit.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/TimeUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/TimeUnit.java 2014-05-21 13:01:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/TimeUnit.java 2014-08-26 08:03:20 +0000
@@ -100,11 +100,23 @@
this.second = second;
}
+ /**
+ * Convert a Joda-Time DateTime object to a TimeUnit
+ *
+ * @param dateTime DateTime object to convert
+ * @return TimeUnit object created from given DateTime
+ */
public static TimeUnit fromDateTime( DateTime dateTime )
{
return new TimeUnit( dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute() );
}
+ /**
+ * Convert a JDK Calendar to TimeUnit object
+ *
+ * @param calendar Calendar to convert
+ * @return TimeUnit object created from given Calendar
+ */
public static TimeUnit fromJdkCalendar( Calendar calendar )
{
int amPm = calendar.get( Calendar.AM_PM );
@@ -113,6 +125,12 @@
calendar.get( Calendar.SECOND ) );
}
+ /**
+ * Convert a JDK Date to TimeUnit object
+ *
+ * @param date Date to convert
+ * @return TimeUnit object created from given Date
+ */
public static TimeUnit fromJdkDate( Date date )
{
return fromDateTime( new DateTime( date.getTime() ) );
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2014-08-25 06:03:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2014-08-26 08:03:20 +0000
@@ -63,19 +63,19 @@
{
// cache for speeding up period lookup, uses calendar.name() + periodType.getName() + date.toString() as key
private static Cache<String, Period> periodCache = CacheBuilder.newBuilder()
- .expireAfterWrite( 5, TimeUnit.MINUTES )
- .initialCapacity( 5000 )
+ .expireAfterAccess( 5, TimeUnit.MINUTES )
+ .initialCapacity( 10000 )
.maximumSize( 30000 )
.build();
private String getCacheKey( Date date )
{
- return getCalendar().name() + "-" + getName() + "-" + date.toString();
+ return getCalendar().name() + getName() + date.getTime();
}
private String getCacheKey( org.hisp.dhis.calendar.Calendar calendar, Date date )
{
- return calendar.name() + "-" + getName() + "-" + date.toString();
+ return calendar.name() + getName() + date.getTime();
}
/**