Rostislav V
Rostislav V

Reputation: 1798

Cannot find cache named

I'm trying to use gemfire in my app to do caching. Here's my properties:

<context:component-scan base-package="my-base-package"/>
<context:annotation-config/>

<!-- Gemfire transation manager -->
<gfe:transaction-manager id="transactionManager" cache-ref="propertyGemfireCache"/>

<!-- Gemfire properties -->
<util:properties id="gemfire-props"
                 location="classpath:conf/environments/gemfire.properties"/>

<!-- Gemfire Client cache -->
<gfe:client-cache id="propertyGemfireCache" properties-ref="gemfire-props"
                  pool-name="gemfire-pool" pdx-serializer-ref="pdxSerializer" pdx-persistent="true"/>

<!-- Gemfire PDX serializer -->
<bean id="pdxSerializer" class="com.gemstone.gemfire.pdx.ReflectionBasedAutoSerializer">
    <property name="serializableClasses">
        <list>
            <value>com\.acmecorp\.enterprise\.property\..*,java\.util\..*</value>
        </list>
    </property>
</bean>

<!-- Gemfire connection pool -->
<bean id="gemfire-pool" class="org.springframework.data.gemfire.client.PoolFactoryBean">
    <property name="subscriptionEnabled" value="true"/>
    <property name="freeConnectionTimeout" value="60000"/>
    <property name="prSingleHopEnabled" value="true"/>
    <property name="locators" ref="gemfireLocators"/>
</bean>

<bean id="gemfireCacheManager" class="org.springframework.data.gemfire.support.GemfireCacheManager"
      p:cache-ref="propertyGemfireCache"/>

<gfe:client-region id="myRegion" name="${cache.region.name}" statistics="true"
                   cache-ref="propertyGemfireCache" shortcut="LOCAL">
    <gfe:region-ttl timeout="86400"/>
</gfe:client-region>
<bean id="myTemplate" class="org.springframework.data.gemfire.GemfireTemplate">
  <property name="region" ref="myRegion"/>
</bean>
<cache:advice id="myAdvice" cache-manager="gemfireCacheManager">
    <cache:caching>
        <cache:cacheable cache="myRegion" method="getSomeData"
                         key="''+#data"/>
    </cache:caching>
</cache:advice>

<aop:config>
    <aop:advisor advice-ref="myAdvice"
                 pointcut="execution( * *..ServiceImpl.getData(..)) and within(another-my-package.service.impl..*)"/>
</aop:config>

Property cache.region.name is equal to correct_region_name. If I run my app i will get an error like:

Cannot find cache named 'myRegion' for CacheableOperation[] caches=[myRegion]

But if I replace "myRegion" with the correct region, which is correct_region_name. So it would look like this:

<cache:cacheable cache="correct_region_name" method="getSomeData"
                         key="''+#data"/>

Everything will work perfectly, but i don't need that. Any Help?

Upvotes: 1

Views: 6518

Answers (2)

John Blum
John Blum

Reputation: 7981

Spring (Data GemFire) looks up the Cache "name" in Spring's Cache Abstraction by the name of the Region (a.k.a. Cache; which is not necessarily the bean ID, which is set here, since the RegionLookupFactoryBean implements BeanNameAware).

You might try...

<cache:cacheable cache="${gemfire.region.name}" method="getSomeData" key="''+#data"/>

Upvotes: 1

dturanski
dturanski

Reputation: 1723

I think there may be an issue with using the property place holder ${cache.region.name} in the client-cache config and the order in which Spring resolves these things. Does it work if you hard code the region name there?

Upvotes: 0

Related Questions