接口 SuperCacheManager<T>

类型参数:
T - 实体
所有超级接口:
com.baomidou.mybatisplus.extension.repository.IRepository<T>, com.baomidou.mybatisplus.extension.service.IService<T>, SuperManager<T>
所有已知实现类:
SuperCacheManagerImpl

public interface SuperCacheManager<T> extends SuperManager<T>
基于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
  • 方法概要

    修饰符和类型
    方法
    说明
    void
    清理缓存
    void
    清理缓存
    void
    delCache(Collection<?> idList)
    清理缓存
    void
    delCache(T model)
    清理缓存
    根据ID,批量查询缓存。
    <E> Set<E>
    findCollectByIds(List<Long> keyIdList, Function<Long,CacheKey> cacheBuilder, Function<Long,List<E>> loader)
    根据id 批量查询缓存
    根据id 先查缓存,再查db
    根据 key 查询缓存中存放的id,缓存不存在根据loader加载并写入数据,然后根据查询出来的id查询 实体
    void
    刷新缓存
    void
    setCache(T model)
    设置缓存

    从接口继承的方法 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

      T getByIdCache(Serializable id)
      根据id 先查缓存,再查db
      参数:
      id - 主键
      返回:
      对象
    • getByKey

      T getByKey(CacheKey key, Function<CacheKey,Object> loader)
      根据 key 查询缓存中存放的id,缓存不存在根据loader加载并写入数据,然后根据查询出来的id查询 实体
      参数:
      key - 缓存key
      loader - 加载器
      返回:
      对象
    • 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 - 主键id
      loader - 回调
      返回:
      对象集合
    • 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

      void refreshCache(List<Long> ids)
      刷新缓存
    • clearCache

      void clearCache(List<Long> ids)
      清理缓存
    • delCache

      void delCache(Serializable... ids)
      清理缓存
      参数:
      ids -
    • delCache

      void delCache(Collection<?> idList)
      清理缓存
      参数:
      idList -
    • delCache

      void delCache(T model)
      清理缓存
      参数:
      model -
    • setCache

      void setCache(T model)
      设置缓存
      参数:
      model -