JBoss Community

How to do jboss caching

reply from Amol Umrani in JBoss Cache - View the full discussion

Hello Navin,

 

Thanks for help.

 

I am doing as follows..

 

public class SimpleCaching
{
    try
    {
        GlobalConfiguration myGlobalConfig = new GlobalConfiguration();
        // configure myGlobalConfig accordingly
        EmbeddedCacheManager manager = new DefaultCacheManager(myGlobalConfig);

 

        Configuration config = new Configuration();
        // configure your config bean accordingly
        manager.defineConfiguration("myCustomCache", config);
        Cache customCache = manager.getCache("myCustomCache");

 


        customCache.put("key", "value");

 

        customCache.containsKey("key");
        customCache.remove("key");

 

        customCache.isEmpty();

 

        // remember that Cache extends ConcurrentMap!

 

        customCache.put("key", "value");
        customCache.putIfAbsent("key", "newValue");
        customCache.clear();
    }catch(CacheException ex){
        System.out.println(ex.getMessage());
    }
}

 

This is as per 5 minutes tutorial of infinispan.

 

My question is it right way to write the code for caching...

 

We are using JPA and i come to know we required to configure infinispan for second level cache in persistence.xml..

 

so in this code where i should pass this xml?

 

Please help me regarding this..

 

 

Thnks,

Amol

Reply to this message by going to Community

Start a new discussion in JBoss Cache at Community