1

i am using JCS cache in my application . I am updating jcs cache data from Java Application (Main Method). And Accessing it with another tomcat application( war). My Problem is i am not getting updated cache data for tomcat application.? Only When restarting the tomcat i am getting latest cache tomcat data..

How can i get latest cache data without restarting the tomcat?

Suresh
  • 11
  • 4

2 Answers2

0

What you are doing is not very clear to me. How is the cache shared between your two applications ? So far, it looks like you are using two different cache instances, one per application. If it is indeed the case and if you are using in memory cache, you cannot expect that an update in one application shows up in the second one.

Emmanuel Guiton
  • 1,315
  • 13
  • 24
  • Thanks for your comment @Emmanuel Guiton. Yes you are right i am using two instances in two different applications . I am updating the cache data with one instance. I need the updated cache data in the second instance(which is in tomcat) with out restarting the tomcat. Note : i am getting updated cache data in second application only after restarting tomcat. Which is not good idea to restart tomcat every time. – Suresh May 04 '17 at 05:49
  • Again, you did not tell how is your cache shared between the two applications. And what kind of cache do you use (disk, database, in memory ...)? – Emmanuel Guiton May 04 '17 at 11:53
  • I am Using JCS disk cache . The below is the sample code. Application 1: Inserting the data in to the cache.(Java Main Method) **private JCS jcsCache; jcsCache=JCS.getInstance("keywords"); jcsCache.put(keywordName,keywordData);** Application 2: Fetching the cache data.(Tomcat Application) ** private JCS jcsCache;** **jcsCache = JCS.getInstance("keywords");** **List cachedData = (List) jcsCache.get(stateName);**(If data exists it will return data otherwise it will return null.) – Suresh May 05 '17 at 09:40
0

I am not so much of an expert in using JCS, but I do not think the disk cache is designed to be able to share the cache between different applications. Keys are kept in memory. Each of your applications will have its own knowledge of existing keys, knowledge they do not share nor synchronize. Did you try writing in the cache from both applications ? You may simply end up corrupting your cache.

If you need to share data between different applications, I do believe that cache is not the solution. It should be performed outside of the cache.

Note that you can use lateral TCP cache or RMI cache to distribute cached data. These auxiliary caches do manage cache updates and synchronization.

Emmanuel Guiton
  • 1,315
  • 13
  • 24