Skip to content

Commit ae0f75c

Browse files
Document the caches configuration providers
1 parent d9ce8d0 commit ae0f75c

File tree

1 file changed

+94
-7
lines changed

1 file changed

+94
-7
lines changed

doc/reference/modules/nhibernate_caches.xml

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<chapter id="caches">
33
<title>NHibernate.Caches</title>
44

5-
65
<abstract id="NHibernate.Caches-abstract">
76
<title>What is NHibernate.Caches?</title>
87
<formalpara>
@@ -243,6 +242,43 @@
243242
</para>
244243
</section>
245244

245+
<section id="NHibernate.Caches.ConfigurationProvider">
246+
<title>Using a custom configuration provider</title>
247+
248+
<para>
249+
Most caches have their own configuration section. By default, the cache attempts to read its configuration section
250+
through the .Net <literal>ConfigurationManager</literal>. Some environments do not support it, especially when
251+
running under .Net Core. The .Net Core compatible caches provide a way to set a custom configuration provider, through
252+
their <literal>NHibernate.Caches. cache specific namespace .ConfigurationProvider</literal> class.
253+
</para>
254+
255+
<para>
256+
To disable the configuration provider, in case you configure the cache entirely programmatically,
257+
set its <literal>ConfigurationProvider.Current</literal> property to <literal>null</literal>.
258+
</para>
259+
260+
<programlisting><![CDATA[ConfigurationProvider.Current = null;]]></programlisting>
261+
262+
<para>
263+
To provide directly the <literal>System.Configuration.Configuration</literal> instance to use, call
264+
the cache <literal>ConfigurationProvider.SetConfiguration</literal> method.
265+
</para>
266+
267+
<programlisting><![CDATA[ConfigurationProvider.SetConfiguration(yourConfig);]]></programlisting>
268+
269+
<para>
270+
You may also derive a custom provider from the <literal>ConfigurationProvider</literal> of the cache,
271+
implements its abstract method <literal>GetConfiguration</literal>, and assign an instance of your
272+
custom provider to the cache <literal>ConfigurationProvider.Current</literal> property.
273+
</para>
274+
275+
<para>
276+
Changes of the <literal>ConfigurationProvider.Current</literal> property value are to be done very
277+
early in the application lifecycle, before building any session factory using the cache provider or
278+
before any other call on the cache API. Otherwise they will not be taken into account.
279+
</para>
280+
</section>
281+
246282
<section id="NHibernate.Caches.Prevalence">
247283
<title>Prevalence Cache Configuration</title>
248284
<para>
@@ -251,7 +287,7 @@
251287
full path. If the directory doesn't exist, it will be created.
252288
</para>
253289
<para>
254-
The <literal>prevalenceBase</literal> setting can only be set programmatically through on the NHibernate
290+
The <literal>prevalenceBase</literal> setting can only be set programmatically through the NHibernate
255291
configuration object, by example with <literal>Configuration.SetProperty</literal>.
256292
</para>
257293
</section>
@@ -260,6 +296,11 @@
260296
<title>SysCache Configuration</title>
261297
<para>
262298
SysCache relies on <classname>System.Web.Caching.Cache</classname> for the underlying implementation.
299+
This is a .Net Framework only library, since <literal>System.Web.Caching</literal> is available neither
300+
in the .Net Standard nor in .Net Core.
301+
</para>
302+
303+
<para>
263304
The following NHibernate configuration settings are available:
264305
</para>
265306

@@ -316,12 +357,18 @@
316357
<title>SysCache2 Configuration</title>
317358

318359
<para>
319-
SysCache2 can use SqlCacheDependencies to invalidate cache regions when data in an underlying SQL Server
360+
SysCache2 uses <literal>System.Web.Caching</literal> like SysCache, but can use <literal>SqlCacheDependencies</literal>
361+
to invalidate cache regions when data in an underlying SQL Server
320362
table or query changes. Query dependencies are only available for SQL Server 2005 or higher. To use the cache
321363
provider, the application must be setup and configured to support SQL notifications as described in the
322364
MSDN documentation.
323365
</para>
324366

367+
<para>
368+
This is a .Net Framework only library, since <literal>System.Web.Caching</literal> is available neither
369+
in the .Net Standard nor in .Net Core.
370+
</para>
371+
325372
<para>
326373
The following NHibernate configuration settings are available:
327374
</para>
@@ -625,6 +672,7 @@
625672
Its configuration relies on the EnyimMemcached library own configuration, through its
626673
<literal>enyim.com/memcached</literal> configuration section. See
627674
<ulink url="https://github.com/enyim/EnyimMemcached">project site</ulink>.
675+
This is a .Net Framework only library.
628676
</para>
629677
</section>
630678

@@ -633,6 +681,9 @@
633681
<para>
634682
RtMemoryCache relies on <classname>System.Runtime.Caching.MemoryCache</classname> for the
635683
underlying implementation.
684+
</para>
685+
686+
<para>
636687
The following NHibernate configuration settings are available:
637688
</para>
638689

@@ -674,14 +725,24 @@
674725
</rtmemorycache>
675726
</configuration>]]></programlisting>
676727
</example>
728+
729+
<para>
730+
The loading of this section can be customized with the
731+
<literal>NHibernate.Caches.RtMemoryCache.ConfigurationProvider</literal> class. See
732+
<xref linkend="NHibernate.Caches.ConfigurationProvider" />.
733+
</para>
677734
</section>
678735

679736
<section id="NHibernate.Caches.StackExchangeRedis">
680737
<title>NHibernate.Caches.StackExchangeRedis Configuration</title>
681738
<para>
682739
NHibernate.Caches.StackExchangeRedis relies on <classname>StackExchange.Redis</classname> for the
683740
underlying implementation.
684-
The following NHibernate configuration settings are available (also defined in <literal>NHibernate.Caches.StackExchangeRedis.RedisEnvironment</literal>):
741+
</para>
742+
743+
<para>
744+
The following NHibernate configuration settings are available (also defined in
745+
<literal>NHibernate.Caches.StackExchangeRedis.RedisEnvironment</literal>):
685746
</para>
686747

687748
<variablelist>
@@ -975,17 +1036,26 @@
9751036
<cache region="foo" expiration="500" database="1" />
9761037
<cache region="bar" sliding="true" append-hashcode="true" />
9771038
<cache region="baz"
978-
strategy="NHibernate.Caches.StackExchangeRedis.FastRegionStrategy, NHibernate.Caches" />
1039+
strategy="NHibernate.Caches.StackExchangeRedis.FastRegionStrategy, NHibernate.Caches" />
9791040
</redis>
9801041
</configuration>]]></programlisting>
9811042
</example>
1043+
1044+
<para>
1045+
The loading of this section can be customized with the
1046+
<literal>NHibernate.Caches.StackExchangeRedis.ConfigurationProvider</literal> class. See
1047+
<xref linkend="NHibernate.Caches.ConfigurationProvider" />.
1048+
</para>
9821049
</section>
9831050

9841051
<section id="NHibernate.Caches.CoreMemoryCache">
9851052
<title>CoreMemoryCache Configuration</title>
9861053
<para>
9871054
CoreMemoryCache relies on <classname>Microsoft.Extensions.Caching.Memory.MemoryCache</classname> for the
9881055
underlying implementation.
1056+
</para>
1057+
1058+
<para>
9891059
The following NHibernate configuration settings are available:
9901060
</para>
9911061

@@ -1029,6 +1099,12 @@
10291099
</corememorycache>
10301100
</configuration>]]></programlisting>
10311101
</example>
1102+
1103+
<para>
1104+
The loading of this section can be customized with the
1105+
<literal>NHibernate.Caches.CoreMemoryCache.ConfigurationProvider</literal> class. See
1106+
<xref linkend="NHibernate.Caches.ConfigurationProvider" />.
1107+
</para>
10321108
</section>
10331109

10341110
<section id="NHibernate.Caches.CoreDistributedCache">
@@ -1038,6 +1114,9 @@
10381114
implementations. The implementation has to be provided through an <literal>IDistributedCacheFactory</literal>, either
10391115
supplied through configuration or programmatically by affecting
10401116
<literal>CoreDistributedCacheProvider.CacheFactory</literal> before building a session factory.
1117+
</para>
1118+
1119+
<para>
10411120
The following NHibernate configuration settings are available:
10421121
</para>
10431122

@@ -1092,15 +1171,23 @@
10921171
<properties>
10931172
<property name="expiration-scan-frequency">00:10:00</property>
10941173
<property name="size-limit">1048576</property>
1095-
<property name="cache.serializer">NHibernate.Caches.Util.JsonSerializer.JsonCacheSerializer, NHibernate.Caches.Util.JsonSerializer</property>
1174+
<property name="cache.serializer"
1175+
>NHibernate.Caches.Util.JsonSerializer.JsonCacheSerializer, NHibernate.Caches.Util.JsonSerializer</property>
10961176
</properties>
10971177
<cache region="foo" expiration="500" sliding="true" />
10981178
<cache region="noExplicitExpiration" sliding="true" />
1099-
<cache region="specificSerializer" serializer="NHibernate.Caches.Common.BinaryCacheSerializer, NHibernate.Caches.Common" />
1179+
<cache region="specificSerializer"
1180+
serializer="NHibernate.Caches.Common.BinaryCacheSerializer, NHibernate.Caches.Common" />
11001181
</coredistributedcache>
11011182
</configuration>]]></programlisting>
11021183
</example>
11031184

1185+
<para>
1186+
The loading of this section can be customized with the
1187+
<literal>NHibernate.Caches.CoreDistributedCache.ConfigurationProvider</literal> class. See
1188+
<xref linkend="NHibernate.Caches.ConfigurationProvider" />.
1189+
</para>
1190+
11041191
<para>
11051192
CoreDistributedCache does not support <literal>NHibernate.Cache.ICache.Clear</literal>. Clearing the NHibernate
11061193
cache has no effects with CoreDistributedCache.

0 commit comments

Comments
 (0)