NHibernate L2 缓存 - 流畅的 nHibernate 配置
我已成功为 FHN 中的 Get\Load 配置 L2 缓存,但它不适用于使用 ICriteria 接口配置的查询 - 它不会缓存这些查询的结果。
有谁知道为什么?
配置如下:
ICriteria:
return unitOfWork
.CurrentSession
.CreateCriteria(typeof(Country))
.SetCacheable(true);
实体映射:
public sealed class CountryMap : ClassMap<Country>, IMap
{
public CountryMap()
{
Table("Countries");
Not.LazyLoad();
Cache.ReadWrite().IncludeAll();
Id(x => x.Id);
Map(x => x.TwoLetter);
Map(x => x.ThreeLetter);
Map(x => x.Name);
}
}
以及数据库属性的会话工厂配置:
return () => MsSqlConfiguration.MsSql2005
.ConnectionString(BuildConnectionString())
.ShowSql()
.Cache(c => c.UseQueryCache()
.QueryCacheFactory<StandardQueryCacheFactory>()
.ProviderClass(configuration.RepositoryCacheType)
.UseMinimalPuts())
.FormatSql()
.UseReflectionOptimizer();
Cheers
AWC
I've managed to configure the L2 cache for Get\Load in FHN, but it's not working for queries configured using the ICriteria interface - it doesn't cache the results from these queries.
Does anyone know why?
The configurations are as follows:
ICriteria:
return unitOfWork
.CurrentSession
.CreateCriteria(typeof(Country))
.SetCacheable(true);
Entity Mapping:
public sealed class CountryMap : ClassMap<Country>, IMap
{
public CountryMap()
{
Table("Countries");
Not.LazyLoad();
Cache.ReadWrite().IncludeAll();
Id(x => x.Id);
Map(x => x.TwoLetter);
Map(x => x.ThreeLetter);
Map(x => x.Name);
}
}
And the session factory configuration for the database property:
return () => MsSqlConfiguration.MsSql2005
.ConnectionString(BuildConnectionString())
.ShowSql()
.Cache(c => c.UseQueryCache()
.QueryCacheFactory<StandardQueryCacheFactory>()
.ProviderClass(configuration.RepositoryCacheType)
.UseMinimalPuts())
.FormatSql()
.UseReflectionOptimizer();
Cheers
AWC
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过在配置中添加对 UseQueryCache() 方法的调用?
Have you tried adding a call to the UseQueryCache() method in the configuration?