From: Roland Haeder Date: Thu, 15 Oct 2015 16:00:34 +0000 (+0200) Subject: added caching of those count requests (currently unfinished) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=62a29e9adcc653b77101a117def643eb4dcab604;p=jfinancials-war.git added caching of those count requests (currently unfinished) --- 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