8

I am working on cache implementation (exstremescale)for maven multi module project, where i have added below maven dependency

    <dependency>
        <groupId>com.ibm.extremescale</groupId>
        <artifactId>ogclient</artifactId>
        <version>8.6.0.20150901-215917</version>
    </dependency>

Added caching annotation on

@Override
@Cacheable(value = "productDetails", key = "#productId + #orgId")
public Product productRead(final String productId, final String productKey, final String orgId, final CRApplicationEnum sourceSystem) throws IntegrationException {

cache-manager.xml

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">

<cache:annotation-driven />
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager" primary="true">
    <property name="caches">    
        <set>
            <bean class="com.ibm.websphere.objectgrid.spring.ObjectGridCache"
                p:name="eventDetails"  p:map-name="${iev.eventDetails.mapName}"
                p:object-grid-client-ref="wxsGridClient" />

            <bean class="com.ibm.websphere.objectgrid.spring.ObjectGridCache"
                p:name="eventValidationDetails"  p:map-name="${iev.eventValidationDetails.mapName}"
                p:object-grid-client-ref="wxsGridClient" />

            <bean class="com.ibm.websphere.objectgrid.spring.ObjectGridCache"
                p:name="productDetails"  p:map-name="${ipr.productDetails.mapName}"
                p:object-grid-client-ref="wxsGridClient" />

        </set>
    </property>
</bean>
<bean id="wxsCSDomain"
    class="com.ibm.websphere.objectgrid.spring.ObjectGridCatalogServiceDomainBean"
    p:catalog-service-endpoints="${xscale.catalogServiceEndpoint}" />

<bean id="wxsGridClient"
    class="com.ibm.websphere.objectgrid.spring.ObjectGridClientBean"
    p:catalog-service-domain-ref="wxsCSDomain" p:objectGridName="${wxs.objectGridName}" />

Caching is working for only one maven module of the project, i can see the cache interceptor call and for rest of the maven module it is ignoring the @cacheable annotation(it is not going to the interceptor).

We dont have PostConstructor or Self invokation

We are using atomikos as transaction manager and CXF -interceptors which will be executed before coming to caching methods.

Please help me on this

Community
  • 1
  • 1
Sunil Rk
  • 999
  • 6
  • 12
  • 35
  • working in on module and not the others is a bit weird I'd say. The Spring application context doesn't care where your classes were loaded from. Are you using parent/child contexts? – Stephane Nicoll Jun 22 '16 at 08:36
  • While debugging we got to know, the interceptor list which is prepared by JdkDynamicAopProxy class for the bean having cacheable annotation is not adding cache interceptor to the list. – Sunil Rk Jun 23 '16 at 09:12
  • Can you share a sample, that would be much easier. Can you show the bean configuration of that bean? Are you exposing an interface by any chance? – Stephane Nicoll Jun 25 '16 at 10:01

2 Answers2

0

Your comment about JdkDynamixAopProxy and looking at the code makes me think that the method you have annotated with @Cacheable is in a concrete class. And for the annotation on a concrete class to exhibit proper behavior; you need to enable the cglib proxying in your application.

This can be done by adding proxy target class parameter to your cache annotation driven tag.

<cache:annotation-driven proxy-target-class="true"/>

If you dont want to enable class based proxying for your overall application; you can specify the behavior for a particular class by annotating it with this annotation:

@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)

ritesh.garg
  • 3,725
  • 1
  • 15
  • 14
0

Calling methods in the same class bypasses the dynamic proxy and any cross cutting concern like caching, transaction etc which is part of the dynamic proxies logic is also bypassed. So could your problem be Spring cache @Cacheable method ignored when called from within the same class ?

If so, the fix is to use AspectJ compile time or load time weaving.

denov
  • 11,180
  • 2
  • 27
  • 43