My experience with the 2nd level cache has been very frustrating and I decided to not use it all (More on this on the Contrib forum)
While I decided not to use the 2nd level cache, I have some screens where I do display a lot of data using datagrid and paging. I was hoping to cache the results using SetCacheable(). I am not exactly sure why, but using SetCacheable does not work at all!! What do I need to do in order to enable caching of my query results. I put these entries in the nhibernate section of my web.config:
Code:
<add
key="hibernate.cache.provider_class"
value="NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache"
/>
<add
key="relativeExpiration"
value="3000"
/>
Since the provided SetCacheable did not work, I wrote my own little routine to do the caching (which resulted in a dramatic reduction in execution time for each page). However, I need some unique key to be used as the key when I insert the query results in cache. I decided to use criteria.GetHashcode but it does not return unique values based upon the inputs to the criteria object.
May I request a feature addition, for implementation of GetHashcode method on the criteria class, so that a guaranteed unique value is returned, depending upon on the inputs to the criteria class.