NZJames
NZJames

Reputation: 5055

Updating NHibernate cache in different session

I'm developing a website where the WCF webservices will use NHibernate as the database ORM, each users session having it's own NHibernate Session that will be held open at Session level to give them a session DB cache.

Each User has a summary object that contains a list of notifications from other users, such as new messages, new likes etc, similar to how facebook has the notifications at the top that updates regularly to show new likes from other users, comments etc with the little red flag icons.

The summary object will be held at a NHibernate cache level obviously once loaded, and it would be a simple matter to have an AJAX call to check if the object had changed and update the visual flags if any new notifications had been received.

The problem is that any changes to this - such as sending a user a new message, will be made in a different NHibernate session (as each user has their own session and you don't send messages to yourself!) so how can user Y, in session Y, send user X a message and update User X's summary to show 1 new message?

Is the only way to force the code to go to the DB every time for the summary details and not use cache at all for the summary object? I can't see any way you would know how to find the right session even if there was a way to update another session so I'm guessing the only way is to update the DB summary table and for the polling thread that checks for updates to activity to go to the DB each time and ignore cache.

Any thoughts?

Upvotes: 0

Views: 379

Answers (1)

schglurps
schglurps

Reputation: 1387

In the NHibernate guidances, a ISession object should live as short as possible... Your current solution will not scale if your application is used by a large number of users.

Upvotes: 2

Related Questions