-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
document the write-behind-rxjava example
- Loading branch information
Showing
23 changed files
with
534 additions
and
708 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...failsafe/src/test/java/com/github/benmanes/caffeine/examples/resilience/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@CheckReturnValue | ||
package com.github.benmanes.caffeine.examples.resilience; | ||
|
||
import com.google.errorprone.annotations.CheckReturnValue; |
Binary file not shown.
18 changes: 0 additions & 18 deletions
18
examples/write-behind-rxjava/.mvn/wrapper/maven-wrapper.properties
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Using [RxJava][rxjava] observable sequences, you can asynchronously write to an external resource | ||
after updating the cache. This approach offers a potential performance boost by batching write | ||
operations, albeit with a trade-off of potential data inconsistency. | ||
|
||
A [buffer][] operator gathers changes within a specified time window. This window may encompass | ||
multiple updates to the same key so when merging these changes into a single write any outdated | ||
modifications can be discarded. Subsequently, the subscriber is notified to execute the batch | ||
operation. | ||
|
||
```java | ||
var subject = PublishSubject.<Entry<K, V>>create().toSerialized(); | ||
subject.buffer(10, TimeUnit.SECONDS) | ||
.map(entries -> entries.stream().collect( | ||
toMap(Entry::getKey, Entry::getValue, (v1, v2) -> /* latest */ v2))) | ||
.subscribeOn(Schedulers.io()) | ||
.subscribe(entries -> System.out.println(entries)); | ||
|
||
Cache<K, V> cache = Caffeine.newBuilder().build(); | ||
cache.asMap().compute(key, (k, v) -> { | ||
var value = /* mutations */ | ||
subject.onNext(Map.entry(key, value)); | ||
return value; | ||
}); | ||
``` | ||
|
||
[rxjava]: https://github.com/ReactiveX/RxJava | ||
[buffer]: http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Observable.html#buffer-long-java.util.concurrent.TimeUnit- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
plugins { | ||
`java-library` | ||
alias(libs.plugins.versions) | ||
} | ||
|
||
dependencies { | ||
implementation(libs.caffeine) | ||
implementation(libs.rxjava) | ||
|
||
testImplementation(libs.awaitility) | ||
testImplementation(libs.junit) | ||
} | ||
|
||
testing.suites { | ||
val test by getting(JvmTestSuite::class) { | ||
useJUnitJupiter() | ||
} | ||
} | ||
|
||
java.toolchain.languageVersion = JavaLanguageVersion.of( | ||
System.getenv("JAVA_VERSION")?.toIntOrNull() ?: 11) | ||
|
||
tasks.withType<JavaCompile>().configureEach { | ||
javaCompiler = javaToolchains.compilerFor { | ||
languageVersion = java.toolchain.languageVersion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[versions] | ||
awaitility = "4.2.0" | ||
caffeine = "3.1.7" | ||
junit = "5.10.0" | ||
rxjava = "3.1.6" | ||
versions = "0.47.0" | ||
|
||
[libraries] | ||
awaitility = { module = "org.awaitility:awaitility", version.ref = "awaitility" } | ||
caffeine = { module = "com.github.ben-manes.caffeine:caffeine", version.ref = "caffeine" } | ||
junit = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" } | ||
rxjava = { module = "io.reactivex.rxjava3:rxjava", version.ref = "rxjava" } | ||
|
||
[plugins] | ||
versions = { id = "com.github.ben-manes.versions", version.ref = "versions" } |
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
examples/write-behind-rxjava/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-rc-3-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.