小编Jav*_*ire的帖子

带有列表的Spring @Cacheable方法

我在Spring 4.1.4应用程序中使用了最新的Ehcache.我有的是:

class Contact{
    int id;
    int revision;
}    

@Cacheable("contacts")
public List<Contact> getContactList(List<Integer> contactIdList) {
    return namedJdbc.queryForList("select * from contact where id in (:idlist)", Collections.singletonMap("idlist", contactIdList));
}

@CachePut(value="contact", key = "id")
public void updateContact(Contact toUpdate) {
    jdbctemplate.update("update contact set revision = ? where id = ?", contact.getRevision(), contact.getId());
}
Run Code Online (Sandbox Code Playgroud)

我想要实现的是,联系人存储在缓存中,当我getContactList再次调用该方法时,id从缓存中检索已缓存的所有联系人,并且应该正常查询其他联系人然后缓存.然后,此缓存应在更新时更新缓存的联系人实体.

我使用普通的Spring JDBC和Ehcache,没有JPA,也没有Hibernate.

spring ehcache jdbctemplate

8
推荐指数
1
解决办法
2547
查看次数

标签 统计

ehcache ×1

jdbctemplate ×1

spring ×1