Managing a data cache effectively is important for application or service performance, although not necessarily easy to do. A simple and common design with a data cache that occurs and seems to cause problems is the following:
- a process that continually commits new data to a database
- another process executing is a separate virtual machine, typically a web service, marshaling data from the database
em.getEntityManagerFactory().getCache().evictAll();
This seems to work for all cache settings and forces all caches to be cleared. Â Subsequent calls to get data result in getting the latest committed data in the database. This may not be the most efficient way, but it always gets the latest data. For high systems requiring high performance, this won’t wok very well. It would be better to refresh the cache periodically and have all clients just get the latest cached values. But there is still the issue of refreshing the entire cache.
Any suggestions on doing this better are appreciated. But for now, this works consistently across platforms and reasonably quick for small to moderate amounts of data.