How to get NHibernate ISession to cache an entity not retrieved using the primary key

My user object is almost always retrieved by username, and not by its whole surrogate key. Since the username is not a primary key, this means that ISession will not cache it and repeatedly enters the database to obtain the same data.

Is there any way to configure NHibernate to force ISession to cache users retrieved by username?

+2
source share
3 answers

There seems to be no real answer. Yes, if you use a second level cache, no if you use a session cache.

+2
source

The "session cache" is not really a cache, but an entity map.

My suggestion is that you activate the second level cache for requests using a custom provider that stores items in an HttpContext.

+1
source

All Articles