0

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?

Afshar Mohebi
  • 10,479
  • 17
  • 82
  • 126

2 Answers2

1

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.

Community
  • 1
  • 1
Afshar Mohebi
  • 10,479
  • 17
  • 82
  • 126
0

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

tinonetic
  • 7,751
  • 11
  • 54
  • 79