mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-06 14:15:50 +08:00
refactor: 替换新的缓存API
This commit is contained in:
@@ -16,9 +16,9 @@ public interface EnableCacheReactiveCrudService<E, K> extends ReactiveCrudServic
|
||||
ReactiveCache<E> getCache();
|
||||
|
||||
default Mono<E> findById(K id) {
|
||||
return this.getCache()
|
||||
.mono("id:" + id)
|
||||
.onCacheMissResume(ReactiveCrudService.super.findById(Mono.just(id)));
|
||||
return this
|
||||
.getCache()
|
||||
.getMono("id:" + id, () -> ReactiveCrudService.super.findById(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,13 +80,13 @@ public interface EnableCacheReactiveCrudService<E, K> extends ReactiveCrudServic
|
||||
default ReactiveUpdate<E> createUpdate() {
|
||||
return ReactiveCrudService.super
|
||||
.createUpdate()
|
||||
.onExecute((update, s) -> s.doFinally((__) -> getCache().clear().subscribe()));
|
||||
.onExecute((update, s) -> getCache().clear().then(s));
|
||||
}
|
||||
|
||||
@Override
|
||||
default ReactiveDelete createDelete() {
|
||||
return ReactiveCrudService.super
|
||||
.createDelete()
|
||||
.onExecute((update, s) -> s.doFinally((__) -> getCache().clear().subscribe()));
|
||||
.onExecute((update, s) -> getCache().clear().then(s));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@ public class DefaultReactiveAuthenticationManager implements ReactiveAuthenticat
|
||||
|
||||
return cacheManager
|
||||
.<Authentication>getCache("user-auth")
|
||||
.mono(userId)
|
||||
.onCacheMissResume(() -> initializeService.initUserAuthorization(userId));
|
||||
.getMono(userId, () -> initializeService.initUserAuthorization(userId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,16 +24,16 @@ public class CompositeDictDefineRepository extends DefaultDictDefineRepository {
|
||||
|
||||
@EventListener
|
||||
public void handleClearCacheEvent(ClearDictionaryCacheEvent event) {
|
||||
if(StringUtils.isEmpty(event.getDictionaryId())){
|
||||
if (StringUtils.isEmpty(event.getDictionaryId())) {
|
||||
cacheManager.<DictDefine>getCache("dic-define")
|
||||
.clear()
|
||||
.doOnSuccess(r -> log.info("clear all dic cache success"))
|
||||
.subscribe();
|
||||
}else{
|
||||
.clear()
|
||||
.doOnSuccess(r -> log.info("clear all dic cache success"))
|
||||
.subscribe();
|
||||
} else {
|
||||
cacheManager.<DictDefine>getCache("dic-define")
|
||||
.evict(event.getDictionaryId())
|
||||
.doOnSuccess(r -> log.info("clear dict [{}] cache success", event.getDictionaryId()))
|
||||
.subscribe();
|
||||
.evict(event.getDictionaryId())
|
||||
.doOnSuccess(r -> log.info("clear dict [{}] cache success", event.getDictionaryId()))
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,9 +41,9 @@ public class CompositeDictDefineRepository extends DefaultDictDefineRepository {
|
||||
@Override
|
||||
public Mono<DictDefine> getDefine(String id) {
|
||||
return super.getDefine(id)
|
||||
.switchIfEmpty(Mono.defer(() -> cacheManager.<DictDefine>getCache("dic-define")
|
||||
.mono(id)
|
||||
.onCacheMissResume(getFromDb(id))));
|
||||
.switchIfEmpty(Mono.defer(() -> cacheManager
|
||||
.<DictDefine>getCache("dic-define")
|
||||
.getMono(id, () -> getFromDb(id))));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user