I am using the latest Ehcache in my Spring 4.1.4 application. I have:
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 the contacts are stored in the cache, and when I call the getContactList method getContactList , all contacts whose id already cached are retrieved from the cache, and others should be requested in normal mode and then cached. This cache then updates the cached contact entity when it is updated.
I use simple Spring JDBC and Ehcache, no JPAs and no hibernation.
spring jdbctemplate ehcache
Javadesire
source share