我一直在尝试使用流畅的nhibernate实现缓存区域,到目前为止我已经完成了以下工作:
1)在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;
}2)修改我的ClassMap开启缓存,并设置选择地域:
public UserMap()
{
Cache.ReadWrite().Region("User");
...
}希望我已经正确地完成了上面的操作,但我真的不能确定在哪里为每个区域配置优先级和缓存持续时间。你知道怎么做吗?如果你碰巧在上面的代码中发现了缺陷,我将非常感谢你的反馈。
发布于 2010-06-04 01:23:18
您需要在web/app.config的syscache配置中添加此区域的优先级和过期时间。有关使用二级缓存的详细解释,请参阅this excellent post。示例使用的是普通的NHibernate,但是你应该明白了--关于配置syscache的内容在本文的末尾。
https://stackoverflow.com/questions/2964421
复制相似问题