Sharing cache in multiple web applications.
by srinivas raju
Hi,
I m using Jboss Cache 3.2.0 GA.
We've a requirement where one web application will store user details
in the cache and two other webapps will manipulate the cache.
The three webapps will be deployed in same server (Later we are
planning to deploy them in separate servers).
We tried to create the cache from one webapp and retrieve & modify
from other webapp.
Every time when we call DefaultCacheFactory.getCache() it is creating
new cache. If this whole operation is in one webapp, we can create a
public static Cache instance and can use this in the whole
applicaition. But now as we have 3 different webapps this doesn't
seems to be the solution.
We also tried using the CacheManager/CacheManagerImpl to register in
one webapp using .registerCache(...) & to get in othe webapp using
.getCache(..). But we are getting errors. First of all is this
CacheManager is for this situation are not I m not sure.
Below is the code & config I m using:
total-replication.xml: Provided with the JBoss Cache 3.2.0 GA bundle.
Servelt1: (creates cache & stores data in it)
CacheFactory factory = new DefaultCacheFactory();
Cache cache = factory.createCache("total-replication.xml", true);
Node rootNode = cache.getRoot();
Fqn fqn = Fqn.fromString("/sify/srinu");
Node srinuNode = rootNode.addChild(fqn);
srinuNode.put("empDetails",new Employee(1212,"dasdasd"));
System.out.println("All children: " + cache.getRoot().getChildren());
System.out.println("Node' keys: " + srinuNode.getKeys());
Servlet2: (retrieve the cache & manipulate the data)
CacheFactory factory = new DefaultCacheFactory();
Cache cache = factory.createCache("total-replication.xml", true);
I m not sure how to get the same Cache instance in all apps.
Thanks in advance.
14 years, 7 months