JPA Background Cache Update

We have a high-performance Java (J2SE) middleware application where latency is paramount. It uses some persistent data stored in an outdated database, where an outdated application can sometimes modify data. Due to the latency requirement, we plan to cache persistent data using JPA with Hibernate and possibly a cache provider such as Ehcache.

However, when persistent data is updated (by an outdated application), we should be notified as soon as possible. I thought about the expiration of the cache, but then the cache will not be updated until the application makes the next request for data - at this point the latency will be executed due to re-reading the database.

Ideally, we need a cache to return an obsolete value, and in the background, the cache is updated / updated with the latest value from the database at regular intervals.

Is this possible with Ehcache? I have seen SelfPopulatingCache and CacheLoader, but it looks like I am doing a lot of work (I would have to write code for each object). Also, does anyone have an example implementation of CacheLoader? I was hoping for the async update option in Query Cache.

Are there any other technologies that could provide a solution? We are not affiliated with a JPA provider or cache provider.

Can Spring @Cacheable provide a solution? I saw spring ehcache cachable mentions the self-propagating cache area, but it is not clear what that means.

Thanks in advance.

+8
java spring caching jpa ehcache
source share
3 answers

What database are you using?

EclipseLink 2.4 will provide a cache invalidation feature for database events. It is integrated with Oracle's DCN / QCN database. You can also connect something using triggers.

http://wiki.eclipse.org/EclipseLink/Examples/JPA/DCN

You can also explore Oracle GoldenGate, Coherence, and TopLink Grid.

+5
source share

If you can change an outdated application, then one of the options is to send cache invalidation notifications using ActiveMQ . If you cannot change the legacy application, another option is to add the timestamp / rowversion index column to your table and periodically poll it for changes since the previous poll.

+1
source share

I do not know how to do this using EhCache or another component, but the common approach to this problem is to "have 2 caches." Let me explain: you have one cache serving your application with data (this cache will not have any update during application maintenance) and another cache created by a temporary employee with the latest data (you can create a cache every x seconds or every times you get a message that your data has changed). When your new cache is complete, you will replace the old cache with a new one, so your last update cache now serves the application with a 0 cache timeout. As you can see, the problem with this approach is that the client can see outdated data while your new cache is not complete. And, of course, this is a very expensive method (you will have too many caches in memory and too often create a new cache).

+1
source share

All Articles