我们在NHibernate 4 (.net 4)应用程序中使用.net 4。据我所知,当涉及到二级缓存时,NHibernate 4的行为发生了一些变化。
以下行为似乎已经改变(如果我错了,请纠正我):
在我看来,第二级只适用于下列情况:
using (var hibSession = SessionFactory.OpenSession())
{
// Second level cache working
var entity = hibSession.Get<ChachedEntity>(7); // second level cache working
var parent = entity.ParentElement; // second level cache working because n:1
// Probably working (not tested)
var elements = hibSession.Query<ChachedEntity>().Cacheable().Take(30).ToList(); // guessed behaviour: query-cache selects id's and then then uses second level cache
// second level cache NOT Working
var children = entity.ChildCollectionWithCachableEntities; // second level cache NOT working because 1:n (!!)
}我现在的问题是:
提前感谢
发布于 2016-03-17 20:51:55
交易仍然是需要的。当您开始更新一些缓存实体时,如果不使用它们,将立即禁用缓存。(请看这里为什么,我最近被最新的NH版本咬了。为什么我忽略了交易?没有借口..。此外,在Server中启用read committed snapshot,消除了涉及只读只读提交查询的死锁。)
集合缓存工作,但必须在集合映射中配置。将<cache usage="..." />节点添加到需要缓存的集合和其他集合中。它们包含的实体也必须是可缓存的,这样才能真正有用。(集合缓存只缓存相关实体的主键。)
在您的查询机制中,如果查询是可缓存的,则只从DB加载I,虽然我是NHibernate的长期用户,但我从未见过这种情况。(我使用它的0.9版本,它已经非常成熟,功能丰富。)据我所知,在使用NH4的二级缓存中没有发生任何严重的变化,您可以检查它们的问题和变化跟踪器。
https://stackoverflow.com/questions/27524013
复制相似问题