【发布时间】:2018-05-30 14:57:27
【问题描述】:
目前,我有一种使用 Jooq 存储方法在数据库上进行插入的方法。每次存储记录时,都会将其添加到本地缓存中,该缓存基本上是一个地图,其 Id 来自前面(我需要存储以供以后使用)和保存时生成的 Id。所以基本上:
private Map<String, Integer> cache = new HashMap<>();
public insert(List<Customer> customers>{
//some code to convert Customer to jooq generated CustomerRecord,
//which implements UpdatableRecord from Jooq
record.store();
cache.put(record.getFrontId(), record.getId());
}
public int find(String frontId) { return cache.get(frontId); }
目前一切正常,但管理这一切需要付出很多努力。如何在 Spring @Cacheable 中使用这样的缓存?我从未使用过它,但我尝试添加
@CacheEvict(value="customer", key="#frontId")给find方法,当然调用的时候缓存是空的。
【问题讨论】:
标签: java spring-boot caching jooq