接口 SuperCacheManager<T>
- 类型参数:
T- 实体
- 所有超级接口:
com.baomidou.mybatisplus.extension.repository.IRepository<T>,com.baomidou.mybatisplus.extension.service.IService<T>,SuperManager<T>
- 所有已知实现类:
SuperCacheManagerImpl
基于MP的 IService 新增了几个方法: getByIdCache、getByKey、findByIds、refreshCache、clearCache
其中:
1,getByIdCache 方法 会先从缓存查询,后从DB查询 (取决于实现类)
2、getByKey 根据提供的缓存key查询单个实体,查不到会通过loader回调查询
3、findByIds 根据id批量从缓存查询实体列表
4、refreshCache 刷新缓存
5、clearCache 淘汰缓存
- 作者:
- zuihou
-
字段概要
从接口继承的字段 com.baomidou.mybatisplus.extension.repository.IRepository
DEFAULT_BATCH_SIZE -
方法概要
修饰符和类型方法说明voidclearCache(List<Long> ids) 清理缓存voiddelCache(Serializable... ids) 清理缓存voiddelCache(Collection<?> idList) 清理缓存void清理缓存findByIds(Collection<? extends Serializable> ids, Function<Collection<? extends Serializable>, Collection<T>> loader) 根据ID,批量查询缓存。<E> Set<E>findCollectByIds(List<Long> keyIdList, Function<Long, CacheKey> cacheBuilder, Function<Long, List<E>> loader) 根据id 批量查询缓存根据id 先查缓存,再查db根据 key 查询缓存中存放的id,缓存不存在根据loader加载并写入数据,然后根据查询出来的id查询 实体voidrefreshCache(List<Long> ids) 刷新缓存void设置缓存从接口继承的方法 com.baomidou.mybatisplus.extension.repository.IRepository
count, count, exists, getBaseMapper, getById, getMap, getObj, getOne, getOne, getOneOpt, getOneOpt, getOptById, ktQuery, ktUpdate, lambdaQuery, lambdaQuery, lambdaUpdate, list, list, list, list, listByIds, listByMap, listMaps, listMaps, listMaps, listMaps, listObjs, listObjs, listObjs, listObjs, page, page, pageMaps, pageMaps, query, remove, removeById, removeById, removeById, removeByIds, removeByIds, removeByMap, save, saveBatch, saveOrUpdate, saveOrUpdateBatch, update, update, update, updateBatchById, updateById从接口继承的方法 com.baomidou.mybatisplus.extension.service.IService
removeBatchByIds, saveBatch, saveOrUpdateBatch, updateBatchById从接口继承的方法 top.tangyh.basic.base.manager.SuperManager
getEntityClass, saveBatchSomeColumn, updateAllById
-
方法详细资料
-
getByIdCache
根据id 先查缓存,再查db- 参数:
id- 主键- 返回:
- 对象
-
getByKey
根据 key 查询缓存中存放的id,缓存不存在根据loader加载并写入数据,然后根据查询出来的id查询 实体- 参数:
key- 缓存keyloader- 加载器- 返回:
- 对象
-
findByIds
List<T> findByIds(@NonNull Collection<? extends Serializable> ids, Function<Collection<? extends Serializable>, Collection<T>> loader) 根据ID,批量查询缓存。 若缓存中不存在某条数据,则去数据库中加载数据, 数据库中不存在的数据,直接缓存空缓存。1. 分批次从redis通过 mget 命令获取数据 2. 将redis中不存在的数据(missedIds)通过loader方法 查询出来 3. 将loader方法查询出来的结果(missList) 设置到redis中缓存起来 4. 将loader方法方法未查询出来的结果,设置到redis缓存为 "空值"
注意: 1. ids 参数的数量和返回值的数量一致 2. 若数据库中不存在 ids 的某一个值,返回值对应的数据为 null, 并将会向redis缓存空值
- 参数:
ids- 主键idloader- 回调- 返回:
- 对象集合
-
findCollectByIds
<E> Set<E> findCollectByIds(List<Long> keyIdList, Function<Long, CacheKey> cacheBuilder, Function<Long, List<E>> loader) 根据id 批量查询缓存- 类型参数:
E- 查询的对象- 参数:
keyIdList- id集合cacheBuilder- 缓存key构造器loader- 加载数据的回调方法- 返回:
-
refreshCache
刷新缓存 -
clearCache
清理缓存 -
delCache
清理缓存- 参数:
ids-
-
delCache
清理缓存- 参数:
idList-
-
delCache
清理缓存- 参数:
model-
-
setCache
设置缓存- 参数:
model-
-