我在我的Spring 4.1.4應用程序中使用最新的Ehcache。我所擁有的是:Spring @Cacheable方法與列表
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。