我很高兴使用Fluent NHibernate为几乎所有实体设置公共缓存,如下所示:
public static FluentConfiguration Create(string connStr)
{
return Fluently.Configure()
.Cache(x => x.UseSecondLevelCache().ProviderClass<SysCacheProvider>())
.Mappings(m =>
{
m.FluentMappings
.AddFromAssemblyOf<UserMap>()
.Conventions.Add(
// here the cache is set ReadWrite
Cache.Is(x => x.ReadWrite()),
);
})
}
但是仍然有一些实体我不想缓存它们。我该怎么办?
public class ActivityMap : EntityMap<Activity>
{
public ActivityMap()
{
References<User>(m => m.Executor);
//Note: I'm not want to change the cache but REMOVE the cache!
//Cache.ReadOnly();
}
}
我不确定这是一个真正的解决方案,或者只是在 web.config 的缓存区域节点中设置 expiration=0,但无论它如何工作。