Page 1 of 1

How to make usage of provided caching mechanism?

Posted: Thu Feb 20, 2014 7:35 am
by staleks
Hi,

in my core module, I've created Service and it's implementation.

e.g.
interface PostcodeService and class PostcodeServiceImpl.

There is one method e.g. String retrievePostcodeFrom3rdPartyService(Customer customer);

I want to use cache mechanism provided by broadleaf framework, e.g. blCacheManager.

How to do that?

I've tried adding @Cacheable(value="name", key="customer.id") at interface, defined name of cache in bl-override-cache.xml, but instead of caching this service, in debug mode I see that this method is triggered and code runs through this method.


Thank You

Re: How to make usage of provided caching mechanism?

Posted: Thu Feb 20, 2014 1:33 pm
by phillipuniverse
Did you add the annotation-driven ehcache config (http://ehcache.org/documentation/recipe ... nnotations)?:

Code: Select all

<ehcache:annotation-driven cache-manager="blCacheManager" />

Re: How to make usage of provided caching mechanism?

Posted: Thu Feb 20, 2014 4:03 pm
by staleks
Hi Phillip,

if I just try to add this in one of applicationContext's (e.g. applicationContext.xml of site module), I am getting this error:

Code: Select all

Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'net.sf.ehcache.CacheManager' to required type 'org.springframework.cache.CacheManager' for property 'cacheManager'


This is something that I've expected, since @Cachable annotation is one that comes with Spring 3.1.
And I guess is that BLC framework is using ehCache one.

I saw a link that you've posted, but then it will force me to add one more dependency to project (eventually making it more complex).

I am wondering can this be avoided? Your "glue" for BLC is Spring anyway, right?


ThankYou

Re: How to make usage of provided caching mechanism?

Posted: Thu Feb 20, 2014 5:48 pm
by phillipuniverse
Kinda the blind leading the blind here. From http://www.javacodegeeks.com/2011/02/sp ... orial.html, what if you tried this:

Code: Select all

<bean id="springCacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="blCacheManager"/>


That's equivalent to this, just a slightly nicer syntax using the Spring p: namespace:

Code: Select all

<bean id="springCacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
    <property name="cacheManager" ref="blCacheManager" />
</bean>