Class SuperCacheServiceImpl<M extends SuperCacheManager<Entity>,Id extends Serializable,Entity extends SuperEntity<?>>
java.lang.Object
top.tangyh.basic.base.service.impl.SuperServiceImpl<M,Id,Entity>
top.tangyh.basic.base.service.impl.SuperCacheServiceImpl<M,Id,Entity>
- Type Parameters:
M- ManagerId- IDEntity- 实体
- All Implemented Interfaces:
SuperCacheService<Id,,Entity> SuperService<Id,Entity>
public abstract class SuperCacheServiceImpl<M extends SuperCacheManager<Entity>,Id extends Serializable,Entity extends SuperEntity<?>>
extends SuperServiceImpl<M,Id,Entity>
implements SuperCacheService<Id,Entity>
基于 CacheOps 实现的 缓存实现
默认的key规则: #{CacheKeyBuilder#key()}:id
1,getByIdCache:新增的方法: 先查缓存,在查db 2,removeById:重写 ServiceImpl 类的方法,删除db后,淘汰缓存 3,removeByIds:重写 ServiceImpl 类的方法,删除db后,淘汰缓存 4,updateAllById: 新增的方法: 修改数据(所有字段)后,淘汰缓存 5,updateById:重写 ServiceImpl 类的方法,修改db后,淘汰缓存
- Author:
- zuihou
-
Field Summary
FieldsFields inherited from class top.tangyh.basic.base.service.impl.SuperServiceImpl
entityClass, idClass, managerClass, superManager -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclearCache(List<Long> ids) 清理缓存findByIds(Collection<? extends Serializable> ids, Function<Collection<? extends Serializable>, Collection<Entity>> loader) 可能会缓存穿透getByIdCache(Id id) 根据id 先查缓存,再查db根据 key 查询缓存中存放的id,缓存不存在根据loader加载并写入数据,然后根据查询出来的id查询 实体voidrefreshCache(List<Long> ids) 刷新缓存Methods inherited from class top.tangyh.basic.base.service.impl.SuperServiceImpl
copy, currentIdClass, currentManagerClass, currentModelClass, getById, getEntityClass, getIdClass, getSuperManager, list, listByIds, page, removeByIds, save, saveAfter, saveBatch, saveBefore, updateAfter, updateAllAfter, updateAllBefore, updateAllById, updateBefore, updateByIdMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface top.tangyh.basic.base.service.SuperService
copy, getById, getEntityClass, getIdClass, getSuperManager, list, listByIds, page, removeByIds, save, saveBatch, updateAllById, updateById
-
Field Details
-
cacheOps
-
-
Constructor Details
-
SuperCacheServiceImpl
public SuperCacheServiceImpl()
-
-
Method Details
-
getByIdCache
Description copied from interface:SuperCacheService根据id 先查缓存,再查db- Specified by:
getByIdCachein interfaceSuperCacheService<M extends SuperCacheManager<Entity>,Id extends Serializable> - Parameters:
id- 主键- Returns:
- 对象
-
findByIds
@Transactional(readOnly=true) public List<Entity> findByIds(@NonNull Collection<? extends Serializable> ids, Function<Collection<? extends Serializable>, Collection<Entity>> loader) Description copied from interface:SuperCacheService可能会缓存穿透- Specified by:
findByIdsin interfaceSuperCacheService<M extends SuperCacheManager<Entity>,Id extends Serializable> - Parameters:
ids- 主键idloader- 回调- Returns:
- 对象集合
-
getByKey
@Transactional(readOnly=true) public Entity getByKey(CacheKey key, Function<CacheKey, Object> loader) Description copied from interface:SuperCacheService根据 key 查询缓存中存放的id,缓存不存在根据loader加载并写入数据,然后根据查询出来的id查询 实体- Specified by:
getByKeyin interfaceSuperCacheService<M extends SuperCacheManager<Entity>,Id extends Serializable> - Parameters:
key- 缓存keyloader- 加载器- Returns:
- 对象
-
refreshCache
Description copied from interface:SuperCacheService刷新缓存- Specified by:
refreshCachein interfaceSuperCacheService<M extends SuperCacheManager<Entity>,Id extends Serializable> - Parameters:
ids- 主键
-
clearCache
Description copied from interface:SuperCacheService清理缓存- Specified by:
clearCachein interfaceSuperCacheService<M extends SuperCacheManager<Entity>,Id extends Serializable> - Parameters:
ids- 主键
-