|
125 | 125 | <programlisting>
|
126 | 126 | <property name="cache.provider_class"><literal>XXX</literal></property><co id="hibernate.cache.provider_class-co" linkends="hibernate.cache.provider_class"/>
|
127 | 127 | <property name="cache.default_expiration"><literal>120</literal></property><co id="nhcaches-expiration-co" linkends="nhcaches-expiration"/>
|
| 128 | +<property name="cache.use_sliding_expiration"><literal>true</literal></property><co id="nhcaches-sliding-co" linkends="nhcaches-sliding"/> |
128 | 129 | </programlisting>
|
129 | 130 | <calloutlist>
|
130 | 131 | <callout arearefs="hibernate.cache.provider_class-co" id="hibernate.cache.provider_class">
|
|
138 | 139 | <callout arearefs="nhcaches-expiration-co" id="nhcaches-expiration">
|
139 | 140 | <para>
|
140 | 141 | The <literal>expiration</literal> value is the number of seconds you wish
|
141 |
| - to cache each entry (here two minutes). This example applies to SysCache only. |
| 142 | + to cache each entry (here two minutes). Not all providers support this setting, it may |
| 143 | + be ignored. Check their respective documentation. |
| 144 | + </para> |
| 145 | + </callout> |
| 146 | + <callout arearefs="nhcaches-sliding-co" id="nhcaches-sliding"> |
| 147 | + <para> |
| 148 | + The <literal>use_sliding_expiration</literal> value is whether you wish to use a |
| 149 | + sliding expiration or not. Defaults to <literal>false</literal>. |
| 150 | + Not all providers support this setting, it may be ignored. Check their respective documentation. |
142 | 151 | </para>
|
143 | 152 | </callout>
|
144 | 153 | </calloutlist>
|
|
156 | 165 | <formalpara>
|
157 | 166 | <title>Be careful</title>
|
158 | 167 | <para>
|
159 |
| - Caches are never aware of changes made to the persistent store by another process (though they may be |
160 |
| - configured to regularly expire cached data). As the caches are created at the session factory level, |
161 |
| - they are destroyed with the SessionFactory instance; so you must keep them alive as long as you need |
162 |
| - them. |
163 |
| - </para> |
164 |
| - <para> |
165 |
| - The second level cache requires the use of transactions, be it through transaction scopes or NHibernate |
166 |
| - transactions. Interacting with the data store without an explicit transaction is discouraged, and will |
167 |
| - not allow the second level cache to work as intended. |
| 168 | + <itemizedlist> |
| 169 | + <listitem> |
| 170 | + <para> |
| 171 | + Most caches are never aware of changes made to the persistent store by another process (though they may be |
| 172 | + configured to regularly expire cached data). As the caches are created at the session factory level, |
| 173 | + they are destroyed with the SessionFactory instance; so you must keep them alive as long as you need |
| 174 | + them. |
| 175 | + </para> |
| 176 | + </listitem> |
| 177 | + <listitem> |
| 178 | + <para> |
| 179 | + The second level cache requires the use of transactions, be it through transaction scopes or NHibernate |
| 180 | + transactions. Interacting with the data store without an explicit transaction is discouraged, and will |
| 181 | + not allow the second level cache to work as intended. |
| 182 | + </para> |
| 183 | + </listitem> |
| 184 | + <listitem> |
| 185 | + <para> |
| 186 | + To avoid issues with composite ids and some cache providers, <literal>ToString()</literal> needs to |
| 187 | + be overridden on composite id classes. It should yield an unique string representing the id. If the |
| 188 | + composite id is mapped as a component, overriding the component <literal>ToString()</literal> |
| 189 | + is enough. See <xref linkend="components-compositeid" />. |
| 190 | + </para> |
| 191 | + </listitem> |
| 192 | + </itemizedlist> |
168 | 193 | </para>
|
169 | 194 | </formalpara>
|
170 | 195 | <para>
|
|
184 | 209 | <section id="NHibernate.Caches.SysCache">
|
185 | 210 | <title>SysCache Configuration</title>
|
186 | 211 | <para>
|
187 |
| - As SysCache relies on <classname>System.Web.Caching.Cache</classname> for the underlying implementation, |
188 |
| - the configuration is based on the available options that make sense for NHibernate to utilize. |
| 212 | + As SysCache relies on <classname>System.Web.Caching.Cache</classname> for the underlying implementation. |
| 213 | + Following NHibernate configuration settings are available: |
189 | 214 | </para>
|
190 | 215 |
|
191 | 216 | <variablelist>
|
192 | 217 | <varlistentry>
|
193 | 218 | <term><literal>expiration</literal></term>
|
194 | 219 | <listitem>
|
195 | 220 | Number of seconds to wait before expiring each item.
|
| 221 | + Takes precedence over <literal>cache.default_expiration</literal>. |
| 222 | + If none of them are defined, defaults to <literal>300</literal>. |
| 223 | + </listitem> |
| 224 | + </varlistentry> |
| 225 | + <varlistentry> |
| 226 | + <term><literal>cache.use_sliding_expiration</literal></term> |
| 227 | + <listitem> |
| 228 | + Should the expiration be sliding? A sliding expiration is reinitialized at each get. |
| 229 | + Defaults to <literal>false</literal>. |
196 | 230 | </listitem>
|
197 | 231 | </varlistentry>
|
198 | 232 | <varlistentry>
|
199 | 233 | <term><literal>priority</literal></term>
|
200 | 234 | <listitem>
|
201 | 235 | A numeric cost of expiring each item, where 1 is a low cost, 5 is the highest, and 3 is normal.
|
202 |
| - Only values 1 through 5 are valid. |
| 236 | + Only values 1 through 5 are valid. 6 is a special value corresponding to |
| 237 | + <literal>NotRemovable</literal>, it should not be used. |
203 | 238 | </listitem>
|
204 | 239 | </varlistentry>
|
205 | 240 | </variablelist>
|
206 | 241 |
|
207 | 242 | <para>
|
208 | 243 | SysCache has a config file section handler to allow configuring different expirations and priorities for
|
209 |
| - different regions. Here's an example: |
| 244 | + different regions. Here is an example: |
210 | 245 | </para>
|
211 | 246 |
|
212 | 247 | <example>
|
|
219 | 254 |
|
220 | 255 | <syscache>
|
221 | 256 | <cache region="foo" expiration="500" priority="4" />
|
222 |
| - <cache region="bar" expiration="300" priority="3" /> |
| 257 | + <cache region="bar" expiration="300" priority="3" sliding="true" /> |
223 | 258 | </syscache>
|
224 | 259 | </configuration>]]></programlisting>
|
225 | 260 | </example>
|
|
235 | 270 | MSDN documentation.
|
236 | 271 | </para>
|
237 | 272 |
|
| 273 | + <para> |
| 274 | + Following NHibernate configuration settings are available: |
| 275 | + </para> |
| 276 | + |
| 277 | + <variablelist> |
| 278 | + <varlistentry> |
| 279 | + <term><literal>expiration</literal></term> |
| 280 | + <listitem> |
| 281 | + Number of seconds to wait before expiring each item. |
| 282 | + Takes precedence over <literal>cache.default_expiration</literal>. |
| 283 | + If none of them are defined, defaults to <literal>300</literal>. |
| 284 | + </listitem> |
| 285 | + </varlistentry> |
| 286 | + <varlistentry> |
| 287 | + <term><literal>cache.use_sliding_expiration</literal></term> |
| 288 | + <listitem> |
| 289 | + Should the expiration be sliding? A sliding expiration is reinitialized at each get. |
| 290 | + Defaults to <literal>false</literal>. |
| 291 | + </listitem> |
| 292 | + </varlistentry> |
| 293 | + </variablelist> |
| 294 | + |
238 | 295 | <para>
|
239 | 296 | To configure cache regions with SqlCacheDependencies a <literal>syscache2</literal> config section must be
|
240 | 297 | defined in the application's configuration file. See the sample below.
|
|
456 | 513 | <example>
|
457 | 514 | <title>Relative Expiration</title>
|
458 | 515 |
|
459 |
| - <programlisting><![CDATA[<cacheRegion name="Product" relativeExpiration="300" priority="High" />]]></programlisting> |
| 516 | + <programlisting><![CDATA[<cacheRegion name="Product" relativeExpiration="300" priority="High" useSlidingExpiration="true" />]]></programlisting> |
460 | 517 | </example>
|
461 | 518 |
|
462 | 519 | <example>
|
|
472 | 529 | <listitem>
|
473 | 530 | <para>
|
474 | 531 | Number of seconds that an individual item will exist in the cache before being removed.
|
| 532 | + Defaults to <literal>300</literal> if neither <literal>relativeExpiration</literal> nor |
| 533 | + <literal>timeOfDayExpiration</literal> are defined, and if no expiration settings are |
| 534 | + defined in NHibernate configuration. |
| 535 | + </para> |
| 536 | + </listitem> |
| 537 | + </varlistentry> |
| 538 | + <varlistentry> |
| 539 | + <term><literal>useSlidingExpiration</literal></term> |
| 540 | + <listitem> |
| 541 | + <para> |
| 542 | + Should the expiration be sliding? A sliding expiration is reinitialized at each get. |
| 543 | + Defaults to <literal>false</literal> if not defined in NHibernate configuration. |
475 | 544 | </para>
|
476 | 545 | </listitem>
|
477 | 546 | </varlistentry>
|
|
498 | 567 |
|
499 | 568 | </section>
|
500 | 569 |
|
| 570 | + <section id="NHibernate.Caches.RtMemoryCache"> |
| 571 | + <title>Runtime Memory Configuration</title> |
| 572 | + <para> |
| 573 | + As runtime memory relies on <classname>System.Runtime.Caching.MemoryCache</classname> for the |
| 574 | + underlying implementation. |
| 575 | + Following NHibernate configuration settings are available: |
| 576 | + </para> |
| 577 | + |
| 578 | + <variablelist> |
| 579 | + <varlistentry> |
| 580 | + <term><literal>expiration</literal></term> |
| 581 | + <listitem> |
| 582 | + Number of seconds to wait before expiring each item. |
| 583 | + Takes precedence over <literal>cache.default_expiration</literal>. |
| 584 | + If none of them are defined, defaults to <literal>300</literal>. |
| 585 | + </listitem> |
| 586 | + </varlistentry> |
| 587 | + <varlistentry> |
| 588 | + <term><literal>cache.use_sliding_expiration</literal></term> |
| 589 | + <listitem> |
| 590 | + Should the expiration be sliding? A sliding expiration is reinitialized at each get. |
| 591 | + Defaults to <literal>false</literal>. |
| 592 | + </listitem> |
| 593 | + </varlistentry> |
| 594 | + </variablelist> |
| 595 | + |
| 596 | + <para> |
| 597 | + RtMemoryCache has a config file section handler to allow configuring different expirations for |
| 598 | + different regions. Here is an example: |
| 599 | + </para> |
| 600 | + |
| 601 | + <example> |
| 602 | + <programlisting><![CDATA[<?xml version="1.0" encoding="utf-8" ?> |
| 603 | +<configuration> |
| 604 | + <configSections> |
| 605 | + <section name="syscache" |
| 606 | + type="NHibernate.Caches.SysCache.SysCacheSectionHandler,NHibernate.Caches.SysCache" /> |
| 607 | + </configSections> |
| 608 | +
|
| 609 | + <syscache> |
| 610 | + <cache region="foo" expiration="500" /> |
| 611 | + <cache region="bar" expiration="300" sliding="true" /> |
| 612 | + </syscache> |
| 613 | +</configuration>]]></programlisting> |
| 614 | + </example> |
| 615 | + </section> |
| 616 | + |
501 | 617 | </chapter>
|
0 commit comments