类 SuperCacheManagerImpl<M extends SuperMapper<T>,T extends SuperEntity>
java.lang.Object
com.baomidou.mybatisplus.extension.repository.AbstractRepository<M,T>
com.baomidou.mybatisplus.extension.repository.CrudRepository<M,T>
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl<M,T>
top.tangyh.basic.base.manager.impl.SuperManagerImpl<M,T>
top.tangyh.basic.base.manager.impl.SuperCacheManagerImpl<M,T>
- 类型参数:
M-T-
- 所有已实现的接口:
com.baomidou.mybatisplus.extension.repository.IRepository<T>,com.baomidou.mybatisplus.extension.service.IService<T>,SuperCacheManager<T>,SuperManager<T>
public abstract class SuperCacheManagerImpl<M extends SuperMapper<T>,T extends SuperEntity>
extends SuperManagerImpl<M,T>
implements SuperCacheManager<T>
基于 CacheOps 实现的 缓存实现
默认的key规则: #{CacheKeyBuilder#key()}:id
1,getByIdCache:新增的方法: 先查缓存,在查db 2,removeById:重写 ServiceImpl 类的方法,删除db后,淘汰缓存 3,removeByIds:重写 ServiceImpl 类的方法,删除db后,淘汰缓存 4,updateAllById: 新增的方法: 修改数据(所有字段)后,淘汰缓存 5,updateById:重写 ServiceImpl 类的方法,修改db后,淘汰缓存
- 作者:
- zuihou
-
字段概要
字段从类继承的字段 com.baomidou.mybatisplus.extension.repository.CrudRepository
baseMapper从类继承的字段 com.baomidou.mybatisplus.extension.repository.AbstractRepository
log从接口继承的字段 com.baomidou.mybatisplus.extension.repository.IRepository
DEFAULT_BATCH_SIZE -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected abstract CacheKeyBuilder缓存key 构造器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查询 实体protected ObjectvoidrefreshCache(List<Long> ids) 刷新缓存booleanbooleanremoveByIds(Collection<?> idList) booleanbooleansaveBatch(Collection<T> entityList, int batchSize) booleansaveOrUpdateBatch(Collection<T> entityList, int batchSize) void设置缓存booleanupdateAllById(T model) 根据id修改 entity 的所有字段booleanupdateBatchById(Collection<T> entityList, int batchSize) booleanupdateById(T model) 从类继承的方法 top.tangyh.basic.base.manager.impl.SuperManagerImpl
getEntityClass, getSuperMapper从类继承的方法 com.baomidou.mybatisplus.extension.repository.CrudRepository
getBaseMapper, getSqlStatement从类继承的方法 com.baomidou.mybatisplus.extension.repository.AbstractRepository
executeBatch, executeBatch, getMap, getMapperClass, getObj, getOne, getOneOpt, getSqlSessionFactory, removeById, saveOrUpdate从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 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, removeByIds, removeByMap, saveOrUpdate, update, update, update从接口继承的方法 com.baomidou.mybatisplus.extension.service.IService
removeBatchByIds, saveBatch, saveOrUpdateBatch, updateBatchById从接口继承的方法 top.tangyh.basic.base.manager.SuperManager
getEntityClass, saveBatchSomeColumn
-
字段详细资料
-
MAX_BATCH_KEY_SIZE
protected static final int MAX_BATCH_KEY_SIZE- 另请参阅:
-
cacheOps
-
-
构造器详细资料
-
SuperCacheManagerImpl
public SuperCacheManagerImpl()
-
-
方法详细资料
-
cacheKeyBuilder
缓存key 构造器- 返回:
- 缓存key构造器
-
getByIdCache
从接口复制的说明:SuperCacheManager根据id 先查缓存,再查db- 指定者:
getByIdCache在接口中SuperCacheManager<M extends SuperMapper<T>>- 参数:
id- 主键- 返回:
- 对象
-
findCollectByIds
@Transactional(readOnly=true) public <E> Set<E> findCollectByIds(List<Long> keyIdList, Function<Long, CacheKey> cacheBuilder, Function<Long, List<E>> loader) 从接口复制的说明:SuperCacheManager根据id 批量查询缓存- 指定者:
findCollectByIds在接口中SuperCacheManager<M extends SuperMapper<T>>- 类型参数:
E- 查询的对象- 参数:
keyIdList- id集合cacheBuilder- 缓存key构造器loader- 加载数据的回调方法- 返回:
-
findByIds
@Transactional(readOnly=true) public List<T> findByIds(@NonNull Collection<? extends Serializable> ids, Function<Collection<? extends Serializable>, Collection<T>> loader) 从接口复制的说明:SuperCacheManager根据ID,批量查询缓存。 若缓存中不存在某条数据,则去数据库中加载数据, 数据库中不存在的数据,直接缓存空缓存。1. 分批次从redis通过 mget 命令获取数据 2. 将redis中不存在的数据(missedIds)通过loader方法 查询出来 3. 将loader方法查询出来的结果(missList) 设置到redis中缓存起来 4. 将loader方法方法未查询出来的结果,设置到redis缓存为 "空值"
注意: 1. ids 参数的数量和返回值的数量一致 2. 若数据库中不存在 ids 的某一个值,返回值对应的数据为 null, 并将会向redis缓存空值
- 指定者:
findByIds在接口中SuperCacheManager<M extends SuperMapper<T>>- 参数:
ids- 主键idloader- 回调- 返回:
- 对象集合
-
getByKey
从接口复制的说明:SuperCacheManager根据 key 查询缓存中存放的id,缓存不存在根据loader加载并写入数据,然后根据查询出来的id查询 实体- 指定者:
getByKey在接口中SuperCacheManager<M extends SuperMapper<T>>- 参数:
key- 缓存keyloader- 加载器- 返回:
- 对象
-
removeById
- 指定者:
removeById在接口中com.baomidou.mybatisplus.extension.repository.IRepository<M extends SuperMapper<T>>
-
removeByIds
@Transactional(rollbackFor=java.lang.Exception.class) public boolean removeByIds(Collection<?> idList) - 指定者:
removeByIds在接口中com.baomidou.mybatisplus.extension.repository.IRepository<M extends SuperMapper<T>>
-
save
- 指定者:
save在接口中com.baomidou.mybatisplus.extension.repository.IRepository<M extends SuperMapper<T>>
-
updateAllById
从接口复制的说明:SuperManager根据id修改 entity 的所有字段- 指定者:
updateAllById在接口中SuperManager<M extends SuperMapper<T>>- 覆盖:
updateAllById在类中SuperManagerImpl<M extends SuperMapper<T>,T extends SuperEntity> - 返回:
-
updateById
- 指定者:
updateById在接口中com.baomidou.mybatisplus.extension.repository.IRepository<M extends SuperMapper<T>>
-
saveBatch
@Transactional(rollbackFor=java.lang.Exception.class) public boolean saveBatch(Collection<T> entityList, int batchSize) - 指定者:
saveBatch在接口中com.baomidou.mybatisplus.extension.repository.IRepository<M extends SuperMapper<T>>- 覆盖:
saveBatch在类中com.baomidou.mybatisplus.extension.repository.CrudRepository<M extends SuperMapper<T>,T extends SuperEntity>
-
saveOrUpdateBatch
@Transactional(rollbackFor=java.lang.Exception.class) public boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize) - 指定者:
saveOrUpdateBatch在接口中com.baomidou.mybatisplus.extension.repository.IRepository<M extends SuperMapper<T>>- 覆盖:
saveOrUpdateBatch在类中com.baomidou.mybatisplus.extension.repository.CrudRepository<M extends SuperMapper<T>,T extends SuperEntity>
-
updateBatchById
@Transactional(rollbackFor=java.lang.Exception.class) public boolean updateBatchById(Collection<T> entityList, int batchSize) - 指定者:
updateBatchById在接口中com.baomidou.mybatisplus.extension.repository.IRepository<M extends SuperMapper<T>>- 覆盖:
updateBatchById在类中com.baomidou.mybatisplus.extension.repository.CrudRepository<M extends SuperMapper<T>,T extends SuperEntity>
-
refreshCache
从接口复制的说明:SuperCacheManager刷新缓存- 指定者:
refreshCache在接口中SuperCacheManager<M extends SuperMapper<T>>
-
clearCache
从接口复制的说明:SuperCacheManager清理缓存- 指定者:
clearCache在接口中SuperCacheManager<M extends SuperMapper<T>>
-
delCache
从接口复制的说明:SuperCacheManager清理缓存- 指定者:
delCache在接口中SuperCacheManager<M extends SuperMapper<T>>
-
delCache
从接口复制的说明:SuperCacheManager清理缓存- 指定者:
delCache在接口中SuperCacheManager<M extends SuperMapper<T>>
-
delCache
从接口复制的说明:SuperCacheManager清理缓存- 指定者:
delCache在接口中SuperCacheManager<M extends SuperMapper<T>>
-
setCache
从接口复制的说明:SuperCacheManager设置缓存- 指定者:
setCache在接口中SuperCacheManager<M extends SuperMapper<T>>
-
getId
-