We have a high performance Java (J2SE) middleware app where latency is of utmost importance. It uses some standing data held in a legacy database, where a legacy application may occaisionally modify the data. Because of the latency requirement, we are planning to Cache the standing data, utilising JPA with Hibernate and maybe a cache provider such as Ehcache.
However, when the standing data is updated (by the legacy app) we need to be notified of this as soon as possible. I was thinking of setting an expiry on the cache, but then cache will not be refreshed until the next request for the data is made by the application - at which point the latency will be effected due to the database re-read.
Ideally we need the cache to return a stale value, and in the background the cache is updated/refreshed with the latest value from the database at regular intervals.
Is this possible with Ehcache? I have seen SelfPopulatingCache and CacheLoader, but this seems like I'm doing a lot of work (i'd have to hand write code for each entity). Also, does anyone have an example of a CacheLoader implementation? I was hoping for an async refresh option on the Query Cache.
Are there any other technologies out there that could provide a solution? We aren't bound by JPA provider or cache provider.
Could Spring @Cacheable provide a solution? I've seen spring ehcache cachable mentions self-populating-cache-scope, but its not clear to me what this means.
Thanks in advance.