JBoss Community

cache NULL each time I hit a button

created by barbara b in JBoss Cache Development - View the full discussion

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

Start a new discussion in JBoss Cache Development at Community