refactor: 替换新的缓存API

This commit is contained in:
zhouhao
2023-07-10 16:44:13 +08:00
parent de52152490
commit f91edeb031
3 changed files with 17 additions and 18 deletions

View File

@@ -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));
}
}

View File

@@ -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));
}
}

View File

@@ -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