How to update the cache of the second level?

How to force re-read db data (without turning off the second level cache before reading), and then put it in the cache.

The use case is as follows:

There is a service that uses dictionary data. Service is under heavy load, so performance is imperative. I would like the dictionary data to always be available in the second level cache for the service. Dictionary data can be modified externally, so the cache needs to be updated periodically.

Is it possible to "update" the second-level cache so that other SessionFactory clients do not cause hits in db (they will receive old elements while updated data is updated).

ehcache used as a cache provider, but it can be reasonably changed.

+4
source share
1 answer

From time to time, to cause reading in db, you can install CacheMode in a REFRESH session - data will be extracted from db for this single client and any updates added to the second level cache. Other client requests using normal caching mode will be read from the second level cache without getting into db.

See CacheMode

+4
source

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


All Articles