Can first level cache be used with ICriteria or other APIs?

In NHibernate you can easily use the first level cache when using the Load or Get methods. But what about ICriteria , HQL , Linq-to-NHibernate and QueryOver ? Do they also use first level cache?

+4
source share
2 answers

They use it for returned objects, but requests go directly to db unless you use a second level cache.

Consider this:

 var fooUsingGet = session.Get<Foo>(fooId); var fooQueryById = session.Query<Foo>().Single(f => f.Id == fooId); 

Two queries are executed (one for Get, one for the query), but both variables contain the same object reference.

Now, if you enable the second level cache, do query caching and specify caching for the request:

 var fooQueryById = session.Query<Foo>().Cacheable() .Single(f => f.Id == fooId); var fooQueryByIdAgain = session.Query<Foo>().Cacheable() .Single(f => f.Id == fooId); 

Only one request is executed.

+5
source

No, as I understand it, they do not. They use only the second level cache. The Firs level cache is for Get and Load .

0
source

Source: https://habr.com/ru/post/1338697/


All Articles