Skip to content

Commit

Permalink
doc: add usage in README
Browse files Browse the repository at this point in the history
  • Loading branch information
GangCheng committed Aug 23, 2023
1 parent 4e90a7b commit f282fd1
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,96 @@ ReactiveCacheManager reactiveCacheManager = ReactiveCacheManagerBuilder.newCusto
ReactiveCacheManager reactiveCacheManager;
```

* Caching operation

```java
// Initialize ReactiveCacheManager instance manually with ReactiveCacheManagerBuilder
// Or auto-injected in spring boot context
ReactiveCacheManager reactiveCacheManager;

@Test
void get() {
reactiveCache.monoCache()
.get(cacheKey)
.as(StepVerifier::create)
.expectError(NoSuchCachedReactiveDataException.class)
.verify();
}

@Test
void cacheIfNecessary() {
reactiveCache.monoCache()
.cacheIfNecessary(cacheKey, Duration.ofSeconds(3), Mono.just(true))
.as(StepVerifier::create)
.expectNext(true)
.verifyComplete();
reactiveCache.monoCache()
.get(cacheKey)
.as(StepVerifier::create)
.expectNext(true)
.verifyComplete();
}

@Test
void getMany() {
reactiveCache.fluxCache()
.get(cacheKey)
.as(StepVerifier::create)
.expectError(NoSuchCachedReactiveDataException.class)
.verify();
}

@Test
void cacheManyIfNecessary() {
reactiveCache.fluxCache()
.cacheIfNecessary(cacheKey, Duration.ofSeconds(3), Flux.range(0,3))
.as(StepVerifier::create)
.expectNext(0)
.expectNext(1)
.expectNext(2)
.verifyComplete();
reactiveCache.fluxCache()
.get(cacheKey)
.as(StepVerifier::create)
.expectNext(0)
.expectNext(1)
.expectNext(2)
.verifyComplete();
}

@Test
void evictCache() {
reactiveCache.monoCache()
.evictCache(cacheKey)
.as(StepVerifier::create)
.verifyComplete();
reactiveCache.fluxCache()
.evictCache(cacheKey)
.as(StepVerifier::create)
.verifyComplete();
reactiveCache.monoCache()
.cacheIfNecessary(cacheKey, Duration.ofSeconds(3), Mono.just(true))
.as(StepVerifier::create)
.expectNext(true)
.verifyComplete();
reactiveCache.monoCache()
.evictCache(cacheKey)
.as(StepVerifier::create)
.verifyComplete();
reactiveCache.fluxCache()
.cacheIfNecessary(cacheKey, Duration.ofSeconds(3), Flux.range(0,3))
.as(StepVerifier::create)
.expectNext(0)
.expectNext(1)
.expectNext(2)
.verifyComplete();
reactiveCache.fluxCache()
.evictCache(cacheKey)
.as(StepVerifier::create)
.verifyComplete();
}
```

* For more details, please refer to the source code and the test cases.

#### Note:
Expand Down

0 comments on commit f282fd1

Please sign in to comment.