How to add entire table to cache in spring

对着背影说爱祢 提交于 2019-12-06 14:48:32

found the answer.
It loads the table on first call.
After that we just to read from cache from subsequent calls

@Cacheable("name")
@Override
public Map<String,String> findNameById() {
    log.info("db call");
    return IteratorUtils.toList(bookRepository
            .findAll()
            .iterator())
            .stream()
            .collect(Collectors.toMap(Book::getId,Book::getName));
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!