值未填充到gemfire缓存中

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

APP-context.xml中:

         

测试cache.xml

      info        

我有一个名为TestCache.java的测试类

 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:app-context.xml" }) public class TestCache { @Autowired GemfireTemplate testCache; @Test public void testgetSomeValues() { HashMap map1 = retrieveSomeValues(); HashMap map2 = retrieveSomeValues(); assertEquals(Map1, Map2); } @Cacheable(value = "testCache") public HashMap retrieveSomeValues() { HashMap obj = new HashMap(); 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和使用注释的代码。