【发布时间】:2017-09-28 21:28:26
【问题描述】:
我创建了两个使用Spring Cache 的services。在第一种方法中,我将在应用程序启动时记录所有记录:
@CachePut(value = "items")
public Item save(Item item){
System.out.println("----------------- z cachea udated" + item);
return itemRepository.saveAndFlush(item);
}
因此,当应用程序在最初的步骤中运行时,我会填充我的 cache。然后我得到所有记录:
@Cacheable(value = "items")
public Page<Item> getItems(Pageable pageRequest){
System.out.println("----------------- z cachea PAGEABLE");
Page<Item> all = itemRepository.findAll(pageRequest);
System.out.println("----------------- all" + all.getContent());
return all;
}
然后我使用save() 方法只更新一条记录并再次获取所有记录。在那一刻,我的cache 根本没有改变。在cache 中,所有记录都在第一次调用方法中。如何只更改cache 中受更新影响的记录?
【问题讨论】:
标签: java spring list caching spring-cache