[jboss-dev-forums] [JBoss Cache Development] - cache NULL each time I hit a button

barbara b do-not-reply at jboss.com
Mon Jan 10 10:05:24 EST 2011


barbara b [http://community.jboss.org/people/barbaraboie] created the discussion

"cache NULL each time I hit a button"

To view the discussion, visit: http://community.jboss.org/message/579794#579794

--------------------------------------------------------------
Hello
Before, I used a previous version of JBoss Cache where I simply could use in every bean CacheProvider:

 @In(create=true)
 CacheProvider cacheProvider  

 public void method(){     
      ...     
      List) cacheProvider.get("tree-"+id);

      if (rubriek == null){          
           cacheProvider.put("tree-"+id,getTree());  
      }     
      ...
 }  

and the caching worked just fine through the whole site.

Now I'm trying to work with JBoss Cache 3.2.5.GA and it's not working. Every time I click on a button, the cache is empty. 

I started changing the code in each bean into


CacheFactory factory = new DefaultCacheFactory();
Cache cache = factory.createCache("cache-configuration.xml"); 

public void method(){     
      ...     
      Fqn fqn = Fqn.fromString("/id"+id) 
      List) cache.get(fqn,"tree");       

      if (rubriek == null){          
           cache.put(fqn,"tree",getTree());     
      }     
      ...
 }   

When I tried this code, I saw that the cache was emptied each time I hit a button. I thought the problem was that I start in each bean a new Cache by using factory.createCache("cache-configuration.xml")

So I made a new class that can be used in every bean, so that the cache is only started once:


public class CacheHelper{      
     public static CacheFactory  factory = new DefaultCacheFactory();       
     public static Cache cache = factory.createCache("cache-configuration.xml"); 
}   



and in each bean

public void method(){     
      ...      
      List) CacheHelper.cache.get(fqn,"tree");       
      if (rubriek == null){           
           CacheHelper.cache.put(fqn,"tree",getTree());     
      }     
      ...
} 

But the cache is still empty each time I click on a button.

Is there anyone who can tell me what I'm doing wrong?
Thanks a lot in advance!
Barbara

O, this is my cache-configuration.xml
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/579794#579794]

Start a new discussion in JBoss Cache Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2056]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-dev-forums/attachments/20110110/2cc10007/attachment.html 


More information about the jboss-dev-forums mailing list