Question

The more I read about NHibernate L2 caching, the more it seems to me that you primarily benefit from it only in the following scenario:

  • You are primarily querying by Id, and...
  • You are primarily querying static data, and/or
  • You expect identical queries to be run frequently (which essentially gets us back to querying by Id, because the query cache only stores the set of Id's returned).

Am I wrong in this understanding? If so, what other situations could it produce a big performance boost?

Was it helpful?

Solution

Your question seems to be more related to the Cache pattern than to the NHibernate second level cache. see Cache (computing).

...a cache is a component that transparently stores data so that future requests for that data can be served faster...

And that's it. If your application is doing any performance crictical operations, the second level cache can help you to serve them much more faster.

NHibernate is caching queries by their complete set of parameters (paging, ordering, filters...) so even in simple scenario, providing the home or start page with a list of all articles, employees, tasks... which is served to almost all users ... you can save time and resources.

Whenver there is a change in the underlying data, cache is (could be) cleared, and new data are reloaded.

And because there are very smart Cache providers, you can use the NHibernate and caches even in web-farms. This is the first reading which you should go through:First and Second Level caching in NHibernate

SO: Not only for get by id or static data. Second level cache can improve performance even on transactional application with high traffic. Because even for a very short time, you can take data from a cache (e.g. memeora) and save some milliseconds...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top