]> git.mxchange.org Git - addressbook-war.git/commitdiff
added caching of those count requests (currently unfinished)
authorRoland Haeder <roland@mxchange.org>
Thu, 15 Oct 2015 16:00:34 +0000 (18:00 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 15 Oct 2015 16:00:34 +0000 (18:00 +0200)
src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java

index e69455e72deacfabff406ef38612da7c05fbdbe0..99d51ea2b588dd436c71b3ae49cced6b0e422328 100644 (file)
@@ -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<User, Integer> 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