类 BaseCacheableServiceImpl<MAPPER extends BaseMapper<ENTITY>,ENTITY extends BaseEntity<? extends Serializable>>
- java.lang.Object
-
- com.baomidou.mybatisplus.extension.service.impl.ServiceImpl<MAPPER,ENTITY>
-
- org.shoulder.data.mybatis.template.service.BaseServiceImpl<MAPPER,ENTITY>
-
- org.shoulder.data.mybatis.template.service.BaseCacheableServiceImpl<MAPPER,ENTITY>
-
- 类型参数:
MAPPER-ENTITY-
- 所有已实现的接口:
com.baomidou.mybatisplus.extension.service.IService<ENTITY>,BaseCacheableService<ENTITY>,BaseService<ENTITY>
public abstract class BaseCacheableServiceImpl<MAPPER extends BaseMapper<ENTITY>,ENTITY extends BaseEntity<? extends Serializable>> extends BaseServiceImpl<MAPPER,ENTITY> implements BaseCacheableService<ENTITY>
带缓存的 Service- 作者:
- lym
-
-
字段概要
字段 修饰符和类型 字段 说明 protected Cachecacheprotected static intMAX_BATCH_KEY_SIZE一次查多个 key 时,最多多少个
-
构造器概要
构造器 构造器 说明 BaseCacheableServiceImpl()
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected voidbuildCache(ENTITY model)voidclearCache()清理缓存protected voidevictCache(ENTITY model)protected voidevictCache(Serializable... ids)protected voidevictCache(Collection<? extends Serializable> idList)protected ObjectfetchIdFromEntity(ENTITY model)protected SerializablegenerateCacheKey(Object keywords)缓存key 构造器ENTITYgetByCacheKey(Object key, Function<Object,Object> loader)根据 key 查询缓存中存放的id 缓存不存在则根据loader加载并写入数据ENTITYgetByIdFromCache(Serializable id)查缓存,miss 则从db加载CachegetCache()List<ENTITY>loadByIds(Collection<? extends Serializable> ids, Function<Collection<? extends Serializable>,Collection<ENTITY>> loader)可能会缓存穿透voidrefreshCache()默认全量加载到缓存,量比较大,最好复写booleanremoveById(Serializable id)删除后,逐出缓存booleanremoveByIds(Collection<? extends Serializable> idList)删除后,逐出缓存booleansave(ENTITY model)修改后,逐出缓存booleansaveBatch(Collection<ENTITY> entityList, int batchSize)修改后,逐出缓存booleansaveOrUpdateBatch(Collection<ENTITY> entityList, int batchSize)修改后,逐出缓存voidsetCache(Cache cache)booleanupdateAllById(ENTITY model)修改后,逐出缓存booleanupdateBatchById(Collection<ENTITY> entityList, int batchSize)修改后,逐出缓存booleanupdateById(ENTITY model)修改后,逐出缓存-
从类继承的方法 org.shoulder.data.mybatis.template.service.BaseServiceImpl
saveOrUpdate
-
从类继承的方法 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
closeSqlSession, currentMapperClass, currentModelClass, executeBatch, executeBatch, executeBatch, getBaseMapper, getEntityClass, getMap, getObj, getOne, getSqlStatement, retBool, sqlSessionBatch, sqlStatement
-
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
从接口继承的方法 org.shoulder.data.mybatis.template.service.BaseService
checkEntityAs, createPageQueryWrapper, getBaseMapper, getByBizId, handleBeforePageQuery, handlePageQueryResult, list, list, listByBizIds, lockByBizId, lockById, page, query, removeByBizId, removeByBizIds, saveOrUpdate, updateBatchByBizId, updateBatchByBizId, updateByBizId
-
从接口继承的方法 com.baomidou.mybatisplus.extension.service.IService
count, count, getById, getEntityClass, getMap, getObj, getOne, getOne, ktQuery, ktUpdate, lambdaQuery, lambdaUpdate, list, list, listByIds, listByMap, listMaps, listMaps, listObjs, listObjs, listObjs, listObjs, page, page, pageMaps, pageMaps, query, remove, removeByMap, saveBatch, saveOrUpdate, saveOrUpdateBatch, update, update, update, updateBatchById
-
-
-
-
方法详细资料
-
generateCacheKey
protected Serializable generateCacheKey(Object keywords)
缓存key 构造器- 参数:
keywords- 通常为 id- 返回:
- 缓存key构造器
-
getCache
public Cache getCache()
-
setCache
public void setCache(Cache cache)
-
getByIdFromCache
@Transactional(readOnly=true) public ENTITY getByIdFromCache(Serializable id)
查缓存,miss 则从db加载- 指定者:
getByIdFromCache在接口中BaseCacheableService<MAPPER extends BaseMapper<ENTITY>>- 参数:
id- 主键- 返回:
- v
-
loadByIds
@Transactional(readOnly=true) public List<ENTITY> loadByIds(@NonNull Collection<? extends Serializable> ids, Function<Collection<? extends Serializable>,Collection<ENTITY>> loader)
从接口复制的说明:BaseCacheableService可能会缓存穿透- 指定者:
loadByIds在接口中BaseCacheableService<MAPPER extends BaseMapper<ENTITY>>- 参数:
ids- 主键idloader- 回调- 返回:
- 对象集合
-
getByCacheKey
@Transactional(readOnly=true) public ENTITY getByCacheKey(Object key, Function<Object,Object> loader)
从接口复制的说明:BaseCacheableService根据 key 查询缓存中存放的id 缓存不存在则根据loader加载并写入数据- 指定者:
getByCacheKey在接口中BaseCacheableService<MAPPER extends BaseMapper<ENTITY>>- 参数:
key- 缓存keyloader- 数据加载器- 返回:
- 对象
-
removeById
@Transactional(rollbackFor=java.lang.Exception.class) public boolean removeById(Serializable id)
删除后,逐出缓存- 指定者:
removeById在接口中com.baomidou.mybatisplus.extension.service.IService<MAPPER extends BaseMapper<ENTITY>>
-
removeByIds
@Transactional(rollbackFor=java.lang.Exception.class) public boolean removeByIds(Collection<? extends Serializable> idList)
删除后,逐出缓存- 指定者:
removeByIds在接口中com.baomidou.mybatisplus.extension.service.IService<MAPPER extends BaseMapper<ENTITY>>
-
save
@Transactional(rollbackFor=java.lang.Exception.class) public boolean save(ENTITY model)
修改后,逐出缓存- 指定者:
save在接口中com.baomidou.mybatisplus.extension.service.IService<MAPPER extends BaseMapper<ENTITY>>- 覆盖:
save在类中BaseServiceImpl<MAPPER extends BaseMapper<ENTITY>,ENTITY extends BaseEntity<? extends Serializable>>- 参数:
model- e- 返回:
- b
-
updateAllById
@Transactional(rollbackFor=java.lang.Exception.class) public boolean updateAllById(ENTITY model)
修改后,逐出缓存- 指定者:
updateAllById在接口中BaseService<MAPPER extends BaseMapper<ENTITY>>- 覆盖:
updateAllById在类中BaseServiceImpl<MAPPER extends BaseMapper<ENTITY>,ENTITY extends BaseEntity<? extends Serializable>>- 参数:
model- 实体- 返回:
- 更新成功
-
updateById
@Transactional(rollbackFor=java.lang.Exception.class) public boolean updateById(ENTITY model)
修改后,逐出缓存- 指定者:
updateById在接口中com.baomidou.mybatisplus.extension.service.IService<MAPPER extends BaseMapper<ENTITY>>
-
saveBatch
@Transactional(rollbackFor=java.lang.Exception.class) public boolean saveBatch(Collection<ENTITY> entityList, int batchSize)
修改后,逐出缓存- 指定者:
saveBatch在接口中com.baomidou.mybatisplus.extension.service.IService<MAPPER extends BaseMapper<ENTITY>>- 覆盖:
saveBatch在类中com.baomidou.mybatisplus.extension.service.impl.ServiceImpl<MAPPER extends BaseMapper<ENTITY>,ENTITY extends BaseEntity<? extends Serializable>>
-
saveOrUpdateBatch
@Transactional(rollbackFor=java.lang.Exception.class) public boolean saveOrUpdateBatch(Collection<ENTITY> entityList, int batchSize)
修改后,逐出缓存- 指定者:
saveOrUpdateBatch在接口中com.baomidou.mybatisplus.extension.service.IService<MAPPER extends BaseMapper<ENTITY>>- 覆盖:
saveOrUpdateBatch在类中com.baomidou.mybatisplus.extension.service.impl.ServiceImpl<MAPPER extends BaseMapper<ENTITY>,ENTITY extends BaseEntity<? extends Serializable>>
-
updateBatchById
@Transactional(rollbackFor=java.lang.Exception.class) public boolean updateBatchById(Collection<ENTITY> entityList, int batchSize)
修改后,逐出缓存- 指定者:
updateBatchById在接口中com.baomidou.mybatisplus.extension.service.IService<MAPPER extends BaseMapper<ENTITY>>- 覆盖:
updateBatchById在类中com.baomidou.mybatisplus.extension.service.impl.ServiceImpl<MAPPER extends BaseMapper<ENTITY>,ENTITY extends BaseEntity<? extends Serializable>>
-
refreshCache
public void refreshCache()
默认全量加载到缓存,量比较大,最好复写- 指定者:
refreshCache在接口中BaseCacheableService<MAPPER extends BaseMapper<ENTITY>>
-
clearCache
public void clearCache()
从接口复制的说明:BaseCacheableService清理缓存- 指定者:
clearCache在接口中BaseCacheableService<MAPPER extends BaseMapper<ENTITY>>
-
evictCache
protected void evictCache(Serializable... ids)
-
evictCache
protected void evictCache(Collection<? extends Serializable> idList)
-
evictCache
protected void evictCache(ENTITY model)
-
buildCache
protected void buildCache(ENTITY model)
-
-