Reputation: 4991
I am developing a web application on JAVA EE 6 with SEAM 3, using the full profile on glassfish 3, JSF on the frontend. My main question here is, each user logged in has an inbox, pretty much like facebook, which is constantly updating through ajax, Now my question is. So far I have a CDI @SessionScoped @Named
bean that stores the messages, therefore I'm bloating the user session by keeping all his messages here, these get synchronized eventually.
I could also call the EJB service that retrieves the inbox for every user each time the ajax request is called and hope it will use the cache to load the messages from there instead of flooding my db with queries per ajax request.
My question is, should i do this:
In my cdi bean:
public List<Message> getInbox() {
return inbox; //where inbox is a field that holds all the messages
}
or this:
public List<Message> getInbox() {
return messagingService.findInbox(userdId); //stub to stateless EJB fetching the inbox
}
In other words, should I store the inbox in the session or just fetch it everytime? (Consider i will be using ajax polling and have something like 10 requests per minute per user)
Upvotes: 1
Views: 930
Reputation: 1108722
The JPA cache is applicable to application-wide audience, while the HTTP session is only applicable to the client session. In other words, the data in session scope is duplicated for every single client. It's not really a cache, it's only memory hogging. Use the session scope for real session scoped data only, such as the logged-in user, its preferences, etcetera.
Upvotes: 4