I'm using latest Ehcache in my Spring 4.1.4 application. What I have is:
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());
}
What I want to achieve is, that contacts are stored in the cache, and when I'm calling the getContactList
method again, that all contacts whose id
is already cached are retrieved from the cache and the other ones should be queried normally and then cached. This cache should then update the cached contact entity when it is updated.
I'm using plain Spring JDBC and Ehcache, no JPA and no Hibernate.