簡體   English   中英

值未填充到gemfire緩存中

[英]Values are not being populated into gemfire cache

我有2個xml配置文件,如下所示

app-context.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:tx="http://www.springframework.org/schema/tx"
    xmlns:gfe="http://www.springframework.org/schema/gemfire" xmlns:util="http://www.springframework.org/schema/util"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">


    <context:component-scan
        base-package="com.mycompany.data.testcache" />
    <context:annotation-config />

    <import resource="test-cache.xml" />

    <bean id="testCache" class="org.springframework.data.gemfire.GemfireTemplate">
        <property name="region" ref="region1" />
    </bean>

</beans>

test-cache.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:gfe="http://www.springframework.org/schema/gemfire"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd 
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan
        base-package="com.mycompany.data.testcache" />
    <context:annotation-config />

    <util:properties id="props" location="classpath:test-cache.properties">
        <prop key="log-level">info</prop>
    </util:properties>

    <gfe:cache id="gemfire-cache" properties-ref="props" />

    <gfe:local-region id="region1" cache-ref="gemfire-cache">
        <gfe:cache-listener ref="listener" />
    </gfe:local-region>

    <bean id="listener"
        class="com.mycompany.data.TestLoggingCacheListener" />
</beans>

我有一個名為TestCache.java的測試類

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:app-context.xml" })
public class TestCache {

    @Autowired
    GemfireTemplate testCache;

    @Test
    public void testgetSomeValues() {

        HashMap<String, String> map1 = retrieveSomeValues();

        HashMap<String, String> map2 = retrieveSomeValues();

        assertEquals(Map1, Map2);
    }

    @Cacheable(value = "testCache")
    public HashMap<String, String> retrieveSomeValues() {

        HashMap<String, String> obj = new HashMap<String, String>();
        obj.put("600", "Auto");
        obj.put("601", "Life");

        return obj;
    }

}

但我看到實際上沒有任何內容被緩存到該區域中。 對於方法的兩個retrieveSomeValues()方法調用,實際上是在執行該方法,而不是從緩存中檢索值。

我能知道上述測試課程有什么問題嗎? 我可以知道如何使用@Cacheable來緩存有效的retriveSomeValues()方法的值嗎?

您需要Spring Framework的緩存支持才能使用@Cacheable。 有一個Spring GemFire快速入門示例,該示例顯示如何在以下位置使用帶有@Cacheable批注的GemFire:

https://github.com/SpringSource/spring-gemfire-examples/tree/master/quickstart/spring-cache

您將在此處找到所需的所有內容:應用程序的xml配置,緩存,gemfire和使用注釋的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM