我正在使用 Redis 為 NHibernate 設定快取。我已經遵循了關于如何設定的檔案。唯一的區別是我沒有使用下面的實作。
<property name="cache.use_second_level_cache">true</property>
<屬性名稱="cache.use_query_cache">true</property>
<屬性名稱="cache.provider_class">NHibernate.Caches.Redis.RedisCacheProvider。
NHibernate.Caches.Redis</property>
相反,我使用類似這樣的東西:
return Fluently.Configure()
.資料庫(
PostgreSQLConfiguration.PostgreSQL82.ConnectionString(
c => c.FromConnectionStringWithKey(connectionStringName))
.Driver<NpgsqlDriverExtended>()
.方言<NpgsqlDialectExtended>()
)
.Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<AccountMap>()
.Convention.AddFromAssemblyOf<UnderscoreColumnConvention>()
)
.Cache(c => c.ProviderClass<RedisCacheProvider>()
.UseQueryCache()
.UseSecondLevelCache())。
我還在web.config中添加了以下內容
<configSections>
<section name="redis" type="NHibernate.Caches.StackExchangeRedis.RedisSectionHandler, NHibernate.Caches.StackExchangeRedis" />
</configSections>
<redis>
<cache region="foo_bar" expiration="999" priority="4" />
</redis>
我唯一沒有添加的是下面的內容。
RedisCacheProvider.ConnectionSettings = new RedisCacheConnection("localhost"/span>, 6379) { { "allowAdmin", "true" }, { "abortConnect", "false" }. };
我不知道該把上述代碼段放在哪里。即使我知道在哪里放置它,我也希望它被設定在 web.config 中,但我找不到任何東西可以讓我朝這個方向前進。
請問誰能指引我正確的方向?我也嘗試了依賴性注入,但仍有一個問題:StackExchange.Redis配置字串沒有提供。
uj5u.com熱心網友回復:
對于任何可能有這個問題的人,我都能弄明白。你需要在NHibernate中正確設定Redis,就是添加以下配置。
.ExposeConfiguration(cfg =>
{
cfg.Properties.Add("cache.default_expiration"/span>, "900"/span>)。
cfg.Properties.Add("cache.use_sliding_expiration", "true") 。
cfg.Properties.Add("cache.configuration", "localhost:6379,allowAdmin=true,abortConnect=false")。)
})
最后的結果將是下面這樣的。
return Fluently.Configure()
.資料庫(
PostgreSQLConfiguration.PostgreSQL82.ConnectionString(
c => c.FromConnectionStringWithKey(connectionStringName))
.Driver<NpgsqlDriverExtended>()
.方言<NpgsqlDialectExtended>()
)
.Cache(c =>
c.UseSecondLevelCache()
.UseQueryCache()
.ProviderClass<RedisCacheProvider>())
.ExposeConfiguration(cfg =>
{
cfg.Properties.Add("cache.default_expiration", "900") 。
cfg.Properties.Add("cache.use_sliding_expiration", "true") 。
cfg.Properties.Add("cache.configuration", "localhost:6379,allowAdmin=true, abortConnect=false")。
})
.Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<AccountMap>()
.Convention.AddFromAssemblyOf<UnderscoreColumnConvention>()
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/319227.html
標籤:
上一篇:如何在ASP.NETMVC中只顯示由當前登錄用戶創建的專案
下一篇:不在遞回中迭代
