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;
*/
private User addressbookUser;
+ /**
+ * Map for count of user's shared addresses
+ */
+ private static ConcurrentMap<User, Integer> countSharesList;
+
/**
* Login controller
*/
// Throw again
throw new FaceletException(e);
}
+
+ // Init list
+ // TODO: AddressbookWebBean.countSharesList = new ConcurrentHashMap<>(this.addressbookBean.getUserCountMap());
}
@Override
@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