|
2 | 2 | <chapter id="caches"> |
3 | 3 | <title>NHibernate.Caches</title> |
4 | 4 |
|
5 | | - |
6 | 5 | <abstract id="NHibernate.Caches-abstract"> |
7 | 6 | <title>What is NHibernate.Caches?</title> |
8 | 7 | <formalpara> |
|
243 | 242 | </para> |
244 | 243 | </section> |
245 | 244 |
|
| 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 | + |
246 | 282 | <section id="NHibernate.Caches.Prevalence"> |
247 | 283 | <title>Prevalence Cache Configuration</title> |
248 | 284 | <para> |
|
251 | 287 | full path. If the directory doesn't exist, it will be created. |
252 | 288 | </para> |
253 | 289 | <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 |
255 | 291 | configuration object, by example with <literal>Configuration.SetProperty</literal>. |
256 | 292 | </para> |
257 | 293 | </section> |
|
260 | 296 | <title>SysCache Configuration</title> |
261 | 297 | <para> |
262 | 298 | 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> |
263 | 304 | The following NHibernate configuration settings are available: |
264 | 305 | </para> |
265 | 306 |
|
|
316 | 357 | <title>SysCache2 Configuration</title> |
317 | 358 |
|
318 | 359 | <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 |
320 | 362 | table or query changes. Query dependencies are only available for SQL Server 2005 or higher. To use the cache |
321 | 363 | provider, the application must be setup and configured to support SQL notifications as described in the |
322 | 364 | MSDN documentation. |
323 | 365 | </para> |
324 | 366 |
|
| 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 | + |
325 | 372 | <para> |
326 | 373 | The following NHibernate configuration settings are available: |
327 | 374 | </para> |
|
625 | 672 | Its configuration relies on the EnyimMemcached library own configuration, through its |
626 | 673 | <literal>enyim.com/memcached</literal> configuration section. See |
627 | 674 | <ulink url="https://github.com/enyim/EnyimMemcached">project site</ulink>. |
| 675 | + This is a .Net Framework only library. |
628 | 676 | </para> |
629 | 677 | </section> |
630 | 678 |
|
|
633 | 681 | <para> |
634 | 682 | RtMemoryCache relies on <classname>System.Runtime.Caching.MemoryCache</classname> for the |
635 | 683 | underlying implementation. |
| 684 | + </para> |
| 685 | + |
| 686 | + <para> |
636 | 687 | The following NHibernate configuration settings are available: |
637 | 688 | </para> |
638 | 689 |
|
|
674 | 725 | </rtmemorycache> |
675 | 726 | </configuration>]]></programlisting> |
676 | 727 | </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> |
677 | 734 | </section> |
678 | 735 |
|
679 | 736 | <section id="NHibernate.Caches.StackExchangeRedis"> |
680 | 737 | <title>NHibernate.Caches.StackExchangeRedis Configuration</title> |
681 | 738 | <para> |
682 | 739 | NHibernate.Caches.StackExchangeRedis relies on <classname>StackExchange.Redis</classname> for the |
683 | 740 | 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>): |
685 | 746 | </para> |
686 | 747 |
|
687 | 748 | <variablelist> |
|
975 | 1036 | <cache region="foo" expiration="500" database="1" /> |
976 | 1037 | <cache region="bar" sliding="true" append-hashcode="true" /> |
977 | 1038 | <cache region="baz" |
978 | | - strategy="NHibernate.Caches.StackExchangeRedis.FastRegionStrategy, NHibernate.Caches" /> |
| 1039 | + strategy="NHibernate.Caches.StackExchangeRedis.FastRegionStrategy, NHibernate.Caches" /> |
979 | 1040 | </redis> |
980 | 1041 | </configuration>]]></programlisting> |
981 | 1042 | </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> |
982 | 1049 | </section> |
983 | 1050 |
|
984 | 1051 | <section id="NHibernate.Caches.CoreMemoryCache"> |
985 | 1052 | <title>CoreMemoryCache Configuration</title> |
986 | 1053 | <para> |
987 | 1054 | CoreMemoryCache relies on <classname>Microsoft.Extensions.Caching.Memory.MemoryCache</classname> for the |
988 | 1055 | underlying implementation. |
| 1056 | + </para> |
| 1057 | + |
| 1058 | + <para> |
989 | 1059 | The following NHibernate configuration settings are available: |
990 | 1060 | </para> |
991 | 1061 |
|
|
1029 | 1099 | </corememorycache> |
1030 | 1100 | </configuration>]]></programlisting> |
1031 | 1101 | </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> |
1032 | 1108 | </section> |
1033 | 1109 |
|
1034 | 1110 | <section id="NHibernate.Caches.CoreDistributedCache"> |
|
1038 | 1114 | implementations. The implementation has to be provided through an <literal>IDistributedCacheFactory</literal>, either |
1039 | 1115 | supplied through configuration or programmatically by affecting |
1040 | 1116 | <literal>CoreDistributedCacheProvider.CacheFactory</literal> before building a session factory. |
| 1117 | + </para> |
| 1118 | + |
| 1119 | + <para> |
1041 | 1120 | The following NHibernate configuration settings are available: |
1042 | 1121 | </para> |
1043 | 1122 |
|
|
1092 | 1171 | <properties> |
1093 | 1172 | <property name="expiration-scan-frequency">00:10:00</property> |
1094 | 1173 | <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> |
1096 | 1176 | </properties> |
1097 | 1177 | <cache region="foo" expiration="500" sliding="true" /> |
1098 | 1178 | <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" /> |
1100 | 1181 | </coredistributedcache> |
1101 | 1182 | </configuration>]]></programlisting> |
1102 | 1183 | </example> |
1103 | 1184 |
|
| 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 | + |
1104 | 1191 | <para> |
1105 | 1192 | CoreDistributedCache does not support <literal>NHibernate.Cache.ICache.Clear</literal>. Clearing the NHibernate |
1106 | 1193 | cache has no effects with CoreDistributedCache. |
|
0 commit comments