I am developing an MVC application with NHibernate using a template for each request. In most cases, users just read the data, so I try to use NHibernate's second level cache as follows: I installed SysCache and made all of my persistent objects cacheable (using cache = "non-line-read-write")) and when I launch the application I make calls to loading all commonly used objects from the database as follows:
var all = Session.QueryOver<T>().Cacheable().List<T>()
For evaluation purposes, I trace the execution time of the above call, and for approximately 50,000 results it is ~ 5 seconds for the first time and ~ 2.5 seconds for any subsequent calls to the cached request .... NHibernate Profiler says the database request takes less than 100 ms. what takes so long I tried switching providers, but I got similar (if not worse) results with Velocity and Memcached ... I read almost everything I could find regarding NHibernate and its use of the second level cache, and I think, although I'm probably not quite right that in the above statement what is happening: 50,000 objects are built and their data is stored in object and query caches, and the session timestamp is stored in the timestamp cache. How can this take 5 seconds on an i5 machine? Even if this is normal, as soon as reading the cached data takes 2.5 seconds in subsequent calls without any changes between them? Since I'm relatively new to NHibernate, can any of you help me understand what I'm doing wrong? Any help would be greatly appreciated ... I've been banging my head on the wall for several weeks now ...
source share