How to configure cache regions in fluent nhibernate and syscache2
Posted
by Marcus Oldin
on Stack Overflow
See other posts from Stack Overflow
or by Marcus Oldin
Published on 2010-06-03T08:48:31Z
Indexed on
2010/06/03
8:54 UTC
Read the original article
Hit count: 839
Hi,
I've been trying to implement cache regions with fluent nhibernate and I've done the following so far:
Setup caching in Fluently.Configure():
private static ISessionFactory CreateSessionFactory() { string csStringName = Environment.MachineName;
var nhibConfigProps = new Dictionary<string, string>(); nhibConfigProps.Add("current_session_context_class","web"); var cfg = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008 .ConnectionString(c => c.FromConnectionStringWithKey(csStringName)) .ShowSql() .Cache(cache=>cache.ProviderClass<NHibernate.Caches.SysCache2.SysCacheProvider>().UseQueryCache())) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserMap>()) .ExposeConfiguration(config => config.AddProperties(nhibConfigProps)) .ExposeConfiguration(config=> config.EventListeners.DeleteEventListeners = new IDeleteEventListener[] {new SoftDeleteListener()}) .ExposeConfiguration(config => new SchemaUpdate(config).Execute(false, true)) .BuildSessionFactory(); return cfg; }
Changed my ClassMap to enable cache, and set the region of choice:
public UserMap() { Cache.ReadWrite().Region("User"); ... }
Hopefully I've done the above correctly, but I can't really figure out where to configure the priority and cache duration for each region. Do you know how to do that? And if you happen to find flaws in the above code I'd really appreciate the feedback.
TIA//Marcus
© Stack Overflow or respective owner