0 Replies Latest reply: Jan 10, 2011 10:49 AM by barbara b RSS

cache NULL each time I hit a button

barbara b Newbie

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 rubriek = (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 rubriek = (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 rubriek = (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

 

 

[CODE]<?xml version="1.0" encoding="UTF-8"?>

<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:jboss:jbosscache-core:config:3.2">

<transaction
transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup" />

<eviction wakeUpInterval="5000">
<default algorithmClass="org.jboss.cache.eviction.LRUAlgorithm"
eventQueueSize="200000">
<property name="maxNodes" value="5000" />
<property name="timeToLive" value="3000" />
</default>
<region name="/">
<property name="maxNodes" value="100" />
<property name="timeToLive" value="0" />
</region>
</eviction>

 

<jmxStatistics enabled="true"/>

</jbosscache>[/CODE]