Reputation: 7977
i'm trying to get my head around 2nd Level Caching in Fluent NHibernate. So far i have done the following:
Added the following when i create my session factory:
c.SetProperty("cache.provider_class", "NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache");
c.SetProperty("cache.use_second_level_cache", "true");
c.SetProperty("cache.use_query_cache", "true");
Added Cache.ReadWrite(); against all entities i wish to cache in ClassMap file e.g.
public class CountryMap : ClassMap { public CountryMap() { Table("Countries"); Id(x => x.CountryID); Map(x => x.CountryName); Cache.ReadWrite(); } }
Now i assumed that anytime i try to get an entity which has Cache.ReadWrite() in the mapping it would cache it for the duration of the session factory (singleton). However it appears that this is not the case as the database is hit on every request. Here's a couple questions i have:
I'd appreciate it if you could help. Thanks
Upvotes: 0
Views: 786
Reputation: 22435
Here is a very good explanation for second level cache with nhibernate.
Upvotes: 2
Reputation: 7846
You have to use transactions for the 2nd level cache to be used.
Upvotes: 1