I want to store reference data in the 2nd level cache. I found that for queries that return a single entity, this is indeed faster but when the query returns a collection the cache is much slower than accessing the database.
I know that NHibernate does a lot of work assembling entities from key/value pairs when grabbing them from the cache but I am still surprised at how much slower it is.
Let's say my use case is to populate a dropdown with all available languages, it seems as though NHibernate caching does not help at all with this. Is this typical? Does anyone do something similar with better results than me?
As a comparison, storing such a collection in NCache directly is about 400 times faster than what NHibernate caching (with NCache) delivers.
Extract from NHProf;
-- statement #1 2nd level cache load Language (Hrware.Foundation.Infrastructure.Persistence.Temporal.TemporalIdentifier /* id */)
-- statement #2 2nd level cache collection load Language.CurrentLocalizations (Hrware.Foundation.Infrastructure.Persistence.Temporal.TemporalIdentifier /* id */)
-- statement #3 2nd level cache load LanguageLocalization (Hrware.Foundation.Infrastructure.Persistence.Temporal.TemporalIdentifier /* id */)
-- statement #4 2nd level cache load Language (Hrware.Foundation.Infrastructure.Persistence.Temporal.TemporalIdentifier /* id */)
-- statement #5 2nd level cache collection load Language.CurrentLocalizations (Hrware.Foundation.Infrastructure.Persistence.Temporal.TemporalIdentifier /* id */)
-- statement #6 2nd level cache load LanguageLocalization (Hrware.Foundation.Infrastructure.Persistence.Temporal.TemporalIdentifier /* id */)
-- statement #7 2nd level cache load Language (Hrware.Foundation.Infrastructure.Persistence.Temporal.TemporalIdentifier /* id */)
...
and so on