我想知道如果我誤解了L2緩存如何工作。我試圖緩存一個'HasMany(x => x.Posts)',Bascially我有一個主題,它有許多帖子 - 我的印象是,如果我在主題地圖頂部添加以下內容流利的nHibernate L2緩存不能在HasMany項目工作
Cache.ReadWrite().IncludeAll();
它的緩存映射並具有Manys,直到應用程序的底層數據更改重新啓動?我已經配置我的L2緩存,像這樣
Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("MyAppConString")))
.Cache(c => c.ProviderClass<SysCacheProvider>().UseQueryCache())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<MembershipUserMap>())
Etc…etc..
在我的主題地圖,我有以下(我已刪除了正常的地圖,縮短它的負載),你可以看到在職位的hasMany。
public TopicMap()
{
Cache.ReadWrite().IncludeAll();
Id(x => x.Id);
Map(x => x.Name);
*lots of other normal maps*
References(x => x.Category).Column("Category_Id");
References(x => x.User).Column("MembershipUser_Id");
References(x => x.LastPost).Column("Post_Id").Nullable();
HasMany(x => x.Posts)
.Cascade.AllDeleteOrphan().KeyColumn("Topic_Id")
.Inverse();
*And a few other HasManys*
}
所以,如果我抓住所有的主題,遍歷並執行以下操作
Topic.Posts.Count()
使用SqlProfiler我看到了讓所有帖子每個主題(先打),但如果我重新加載頁面我仍然看到主題查詢的所有獲取帖子?
我錯過了什麼?我認爲這應該緩存?
謝謝我已經'Cache.ReadWrite()。IncludeAll();'在PostMap上,我也會看看這篇文章。 – leen3o