From what I understand, when you execute a query Hibernate automatically checks the Session's cache (first-level) to see if it is there. If there is no match then Hibernate checks the second-level cache (EHCache) which contains instances (if it's enabled for the particular Class) from all Sessions that originated from a particular SessionFactory.
Therefore, the first thing that comes to mind is to give each User their own Session and use that Session for all queries from the User. That way, if a User is requesting the List, the Session will check and see if it's cached before it goes to the database. And since each User has their own Session, they should only have a reference to their List and not anyone elses.
I noticed that your post said that Users are using different Sessions but in order for you to properly utilize the caching you might want to see if you can change that. The only other thing I can think about is creating a SessionFactory for each User, as then the second-level cache can be used per User, but that way is horribly inefficient and will eat up a lot more of your resources than the Session-per-User way which doesn't even require using a second-level cache.
Ben
|