Too Many Cache Calls In The Same Request

NHibernate Profiler has detected a large number of cache calls being made in a single request. Note that this alert is only applicable if you are using a distributed cache, if you are using a local cache, you can safely ignore this alert.

If you are using a distributed cache, however, this alert indicate a possible performance issue that you should be aware of. While making a single call to a cache tends to be significantly faster than calling the database, making a large number of fast calls can end up being slower than making a smaller amount of slow calls.

It is easy to get into situations where you are making hundreds of calls to the cache, and with a distributed cache, this turn out to hundreds of remote calls, which end up being very costly in terms of performance.

To avoid this issue, consider limiting the number of returned results in cache queries (since NHibernate will have to make a cache calls for each returned result). This is a best practice in general, even if you aren't using the cache or using a local cache.

Another common reason for this alert is trying to rely on the cache as a crutch, making large amount of queries and assuming that the cache will make it work fast enough after the first time. The problem with this approach is that hitting the cache does take time, and even when using a local cache, consider the case when the data is expired from the cache or is being purged from the cache.