0

I maintain an application which leverage JCS to hold the cache in JVM (JVM1). This data will be loaded from a database for the first time when the JVM gets started/ restarted.

However the database will be accessed from a different JVM (JVM2) and will help adding data to database.

In order to make sure this additional/ newly added records loaded into cache, we need to restart JVM1 for every addition in the database.

Is there a way we can refresh/load the cache (only for newly added records) in JVM1 for regular intervals (instead of frequent db polling)?

Thanks, Jaya Krishna

1 Answers1

0

Can you not simply have JVM1 first check the in memory cache, and then, if the item is absent in the in-memory cache, check the database cache?

If you, however, need to list all items in existance, of some certain type, and don't want to access the database. Then, for JVM1 to know that there's a new item in the databse, I suppose that either 1) JVM2 would have to send a network message to JVM1 telling it that there're new entries in the database. Or 2) there could be a database trigger that fires when new data is inserted, and sends a network message to JVM1. (But having the database send network messages to an application server feels rather weird I think.) — I think these approaches seem rather complicated though.

Have you considered some kind of new-item-ids table, that logs the IDs of items recently inserted into the database? It could be updated by a database trigger, or by JVM1 and 2 when they write to the databse. Then JVM1 would only need to poll this single table perhaps once per second, to get a list of new IDs, and then it could load the new items from the database.

Finally, have you considered a distributed cache? So that both JVM1 and 2 share the same cache, and JVM1 and 2 writes items to this cache when they insert them into the datbase. (This approach would be somewhat similar to sending network messages between JVM1 and 2, but the distributed cache system would send the messages itself, so you didn't need to write any new code)

KajMagnus
  • 11,308
  • 15
  • 79
  • 127
  • Thanks for the answer. In fact I looked at the trigger part and all we wanted to do was there shouldn't be any database interaction as there won't be any control on the number of hits to database from JVM2 as it goes with number of UI transactions (db updates) on JVM1. But, we tried a little different way by creating a Java stored procedure along with the trigger so that this Java stored proc will control (add/delete entries) the cache on JVM2. – Jaya Krishna Feb 11 '13 at 23:31