Unfortunately, you can't really do this AFAIK. Unless I'm misunderstanding what you mean by "all our web apps", each of your web apps will be running in a completely separate AppDomain, which precludes all of them sharing a single SessionFactory instance. Even if you configure IIS to use a single AppPool for all the ASP.NET apps/sites, each ASP.NET app will still be in a separate AppDomain. This means that anything that needs to be 'shared' between them needs to be 'shared' out-of-process (e.g., across app domains). While it might be *conceptually* possible for you to create your own ISessionFactory instance that then delegates its actual work to some 'real' NHSessionFactory instance via RPC or some other cross-process communication technique, this approach would probably prove so slow and brittle as to be non-viable in a real-world scenario.
Presumably each of your web apps all depend upon the same RDBMS instance(?). In this architecture of yours you would probably be better off looking at an actual database caching solution rather than having your web app(s) use the NH 2nd-level Cache for cross-app caching. Its possible that I'm wrong about this, but I believe you simply cannot do what you're attempting here -Steve B. Steve Bohlen [email protected] http://blog.unhandled-exceptions.com http://twitter.com/sbohlen On Mon, Dec 31, 2012 at 1:35 PM, ut-badboy <[email protected]> wrote: > I have a very specific question regarding the underlying implementation of > the QueryCache (via 2nd level cache) and SessionFactory instances. > > Currently, we have a persistence layer that initializes and configures > nhibernate for all of our web apps. So they all share the same > initialization code. We are also utilizing second level caching, in > particular the query caches. What I have found though is that for each of > the webapps, when they send the same sql, I was expecting if the query was > cached by one web application, then the other web application would not > query the database and retrieve the entities from the 2nd level cache, but > this seems to be not the case. I know that QueryCaches are unique to > SessionFactory, so this may be why I'm seeing this behavior. > > My question is how can I share or ensure that one session factory is > created/used for all of the different web applications. > > Thanks in advance! >
