【发布时间】:2015-09-22 02:49:42
【问题描述】:
我在 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());
}
我想要实现的是,联系人存储在缓存中,当我再次调用getContactList 方法时,所有id 已缓存的联系人都将从缓存中检索,其他联系人应该正常查询然后缓存。然后,此缓存应在更新时更新缓存的联系人实体。
我使用的是纯 Spring JDBC 和 Ehcache,没有 JPA 也没有 Hibernate。
【问题讨论】:
标签: spring ehcache jdbctemplate