How to bridge ehcache 2.x with kaleido?

10 views
Skip to first unread message

kaleidoUser01

unread,
Oct 24, 2013, 1:46:21 PM10/24/13
to kaleid...@googlegroups.com, jerome....@gmail.com, abdus....@gmail.com
Hi Team,
I was trying to bridge ehcache with kaleido but was not clear about the implementation. After going through the kaleido core API, I realized that I have to use 

 EhCacheImpl and EhCacheManagerImpl but how?

After going through the CacheManagerExample    , I tried the following

I have 
 in src/java/main/resources/cacheConfig.properties with the following contents
# cache provider code, and cache configuration file uri
cacheManagers
.myCacheManager.providerCode=ehCache
cacheManagers
.myCacheManager.fileStoreUri=classpath:/src/java/main/resources/ehcache.xml
ehcache.xml holds the ehcache specifig configuration.
Now, how to use EhCacheImpl and EhCacheManagerImpl to get the cache object. So that I can write something like below
public CacheManagerSample01() {

        myCache
= myCacheManager.getCache(YourBean.class);

       
// feed cache with some bean entries
        myCache
.put("bean1", new YourBean("name1", GregorianCalendar.getInstance(), true, 2));
        myCache
.put("bean2", new YourBean("name2", GregorianCalendar.getInstance(), false, 15));
   
}

   
/**
    * method example that use the injected cache
    */

   
public void echo() {
       
System.out.printf("cache name: %s\n", myCache.getName());
       
System.out.printf("cache size: %s\n", myCache.size());
       
System.out.printf("cache entry[%s]: %s\n", "bean1", myCache.get("bean1").toString());
       
System.out.printf("cache entry[%s]: %s\n", "bean2", myCache.get("bean2").toString());
   
}
Please help me.

Jerome Raduget

unread,
Oct 25, 2013, 2:36:10 PM10/25/13
to kaleidoUser01, kaleid...@googlegroups.com
# cache provider code, and cache configuration file uri
cacheManagers.myCacheManager.providerCode=ehCache
cacheManagers.myCacheManager.fileStoreUri=classpath:/ehcache.xml
Should be better

That's the parameter ...providerCode=ehCache which bind the cache implementation to EhCacheManagerImpl / EhCacheImpl
So, you didn't have to use or declare EhCacheManagerImpl directly... , you should use the kaleido interface CacheManager and Cache<...>


You can also checkout some examples from the project kaleido-integration-test/kaleido-it-core 
There are some tests around the cache feature in the classes:  CacheManagerSample01 02 ...
Also have a look to the pom.xml

I'm preparing a simple sample project to start, with all the wiki examples.

-- 
Jérôme
Reply all
Reply to author
Forward
0 new messages