How to force reread db data (without evicting second level cache before reading) and then put it to cache.
The use case is as following:
There is a service, which uses dictionary data. The service experiences high load, so performance is the must. I would like dictionary data to be always available in the second level cache for the service. The dictionary data can be externally modified, so the cache needs to be refreshed periodically.
Is there a possibility to 'refresh' second level cache in such a way that other clients of SessionFactory
will not cause a hit to db (will get old items while updated data is being read).
ehcache
is used as cache provider, but it can be reasonably changed.
Every now and again, to cause a read through to the db, you can set the CacheMode
on the session to REFRESH
- the data will be fetched from the db for that one client, and any updates added to the second-level cache. Other clients querying using the normal cache mode will read from the second-level cache without hitting the db.
See CacheMode