NHibernate Layer 2 Cache with External Updates

I have a web application that is 99% read-only, with a separate service that updates the database at regular intervals (for example, every 10 minutes). How can this service inform the application about the invalidity of the second level cache? Is this really important? (I am not interested if I have too much outdated data) If I do not invalidate the cache, how long does it take to update records (if using SysCache)

+4
source share
2 answers

You can manually manage the second-level cache for a specific object, such as an entity or collection.

From http://knol.google.com/k/fabio-maulo/nhibernate-chapter-16-improving/1nr4enxv3dpeq/19#

For a second-level cache, there are methods defined in ISessionFactory to preempt the cached state of an instance, an entire class, an instance of a collection, or an entire collection role.

  sessionFactory.Evict (typeof (Cat), catId);  // evict a particular cat
 sessionFactory.Evict (typeof (Cat));  // evict all cats
 sessionFactory.EvictCollection ("Eg.Cat.Kittens", catId);  // evict a particular collection of kittens
 sessionFactory.EvictCollection ("Eg.Cat.Kittens");  // evict all kitten collections
+9
source

If you have everything in order with some outdated data, just set the default for expiration that is convenient for you, and you will be installed.

Example:

<property name="cache.default_expiration">120</property> 

This sets the default expiration to two minutes, so you will never see stale data older than this.

+4
source

Source: https://habr.com/ru/post/1312024/


All Articles