【发布时间】:2021-01-19 09:07:04
【问题描述】:
我试图缓存 Map
@Cachable("stocks")
public Map<String,Entry> getEntries(){
//getting entry from database then convert to map
return map;
}
【问题讨论】:
标签: java spring-boot caching ehcache
我试图缓存 Map
@Cachable("stocks")
public Map<String,Entry> getEntries(){
//getting entry from database then convert to map
return map;
}
【问题讨论】:
标签: java spring-boot caching ehcache
这对我有用
@Service
public class OrderService {
public static int counter = 0;
@Cacheable("stocks")
public Map<String, Entry> getEntries() {
counter++;
final Map<String, Entry> map = new HashMap<>();
map.put("key", new Entry(123l, "interesting entry"));
return map;
}
}
这是一个证明计数器没有被调用的测试。
@Test
public void entry() throws Exception {
OrderService.counter = 0;
orderService.getEntries();
assertEquals(1, OrderService.counter);
orderService.getEntries();
assertEquals(1, OrderService.counter);
}
我已将其全部添加到我的github example
【讨论】: