@Cacheable("wantToCache")
public List<Cache> wantToCache(String type) {
List<Cache> caches1 = redisUtil.getCacheList("wantToCache" + type);
if (caches1 != null) {
return caches1;
}
System.out.println("==================");
Condition condition = new Condition(Cache.class);
List<Cache> Caches = casheDao.selectByCondition(condition);
switch (type) {
case 1:
redisUtil.setCacheList("wantToCache" + type, Caches);
}
return Caches;
}
实际上就是比如说我要对一个service做缓存,查询一个表。这个表可能有很多种type。
但是如果直接用@Cacheable注解,redis相当于没有起作用,每次请求不同的type,它都会去更新值,只好自己手动为cache分类,可是这样特别没有效率,请问有没有什么折中的办法呢?
我现在这个办法只是一个很逗很逗的的做法,有没有什么做法,可以让它用很少的代码量,实现一个service,不同查询,只存一次。
而不是查一次更新一次key?