From 62a29e9adcc653b77101a117def643eb4dcab604 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 15 Oct 2015 18:00:34 +0200 Subject: [PATCH] added caching of those count requests (currently unfinished) --- .../beans/addressbook/AddressbookWebBean.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java index e69455e7..99d51ea2 100644 --- a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java @@ -22,6 +22,7 @@ import java.util.Calendar; import java.util.Collections; import java.util.GregorianCalendar; import java.util.List; +import java.util.concurrent.ConcurrentMap; import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; import javax.enterprise.event.Observes; @@ -81,6 +82,11 @@ public class AddressbookWebBean implements AddressbookWebController { */ private User addressbookUser; + /** + * Map for count of user's shared addresses + */ + private static ConcurrentMap countSharesList; + /** * Login controller */ @@ -112,6 +118,9 @@ public class AddressbookWebBean implements AddressbookWebController { // Throw again throw new FaceletException(e); } + + // Init list + // TODO: AddressbookWebBean.countSharesList = new ConcurrentHashMap<>(this.addressbookBean.getUserCountMap()); } @Override @@ -229,8 +238,20 @@ public class AddressbookWebBean implements AddressbookWebController { @Override public Integer countAllUserSharedAddressbooks (final User user) { - // Call EJB - return this.addressbookBean.countAllUserSharedAddressbooks(user); + // Is there cache? + if (AddressbookWebBean.countSharesList.containsKey(user)) { + // Return it instead + return AddressbookWebBean.countSharesList.get(user); + } + + // Call EJB ("expensive") + Integer count = this.addressbookBean.countAllUserSharedAddressbooks(user); + + // Add to list + AddressbookWebBean.countSharesList.put(user, count); + + // Return it + return count; } @Override -- 2.39.5