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

◇◆丶佛笑我妖孽 提交于 2019-12-01 18:31:19

They use it for returning entities, but the queries go straight to the db unless you use the 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 the Get, one for the Query), but both variables contain the same object reference.

Now, if you enable the 2nd level cache, query caching, and specify caching for the query:

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

Only one query will be executed.

No, as I understand they don't. They use only second level cache. Firs level cache is only for Get and Load.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!