ActiveRecordBase.FindAll() does not allow first level cache?

283 views Asked by At

NHibernate's first level cache is available when one use same session. ActiveRecordBase.FindAll() each time creates a new ISession. So such a following can not profit from first level cache:

void test1()
{
  Car.FindAll();
  Car.FindAll();
  Car.FindAll();
}

Is there any solution?

2

There are 2 answers

0
Afshar On BEST ANSWER

Calling several FindAll() does not force several different sessions. They all use a same session. The reason that FindAll() can not benefit is that it internally uses ICriteria and ICriteria itself can not use first level cache. First level cache is available just for Load and Get.

More info available here.

0
Matias Bjørling On

Not as long as you only use a first level cache (session-based). You can, if you enable the second level cache.

See here for information about the liveness of first and second level caches. http://web.archive.org/web/20110514214657/http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/11/09/first-and-second-level-caching-in-nhibernate.aspx