First, for general JBossCache docs, be sure you are familiar with
http://docs.jboss.com/jbcache/1.2.4sp2/TreeCache/en/html/
OK, what I'm going to describe now is a cache that is deployed as part of a
webapp. All the servers in the cluster that deploy the webapp will also deploy
the cache, and those caches will see each other and replicate amongst each
other.
BTW, what I'm about to describe could work in any servlet container. There is
nothing Tomcat specific about it :)
First, you need to create a cache config file. The docs have tons of details
on cache configuration, so I'm not going to get into that Let's say your
config file is called "my-cache-service.xml".
This file needs to be on the webapp classpath. Typically you would place it in
WEB-INF/classes.
The lifecycle of the cache is tied to the webapp lifecycle, so starting and
stopping the cache a ServletContextListener makes sense. In
contextInitialized() you would start the cache:
| TreeCache tree = new TreeCache();
| PropertyConfigurator config = new PropertyConfigurator();
| config.configure(tree, "my-cache--service.xml");
| tree.createService();
| tree.startService();
|
| // Store a ref to the cache so servlets can access it
| event.getServletContext().setAttribute("cache", tree);
|
In contextDestroyed() you would clean up:
| TreeCache tree = (TreeCache)
event.getServletContext().getAttribute("cache");
| if (tree != null)
| {
| tree.stopService();
| tree.destroyService();
| event.getServletContext().removeAttribute("cache");
| }
|
Voila, you have a cache that is accessible to your webapp code via a lookup in
the ServletContext.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3930858#3930858
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3930858
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user