This library provides a cache mechanism relying on RxJava. There are currently two storage implementation :
Two steps are needed :
- Prepare an instance of your storage implementation
- Declare an instance of RxCache with the storage implementation
- Call
fromKey
method from RxCache instance and configure the strategy for this call
final Storage storage = new SnappyDBStorage();
final RxCache rxCache = new RxCache(storage);
rxCache.fromKey("remotedata_%d", 1)
.withStrategy(CacheStrategy.cacheThenAsync())
.withAsync(...) // Your async observable method (Retrofit call for example)
.toObservable()
.subscribe(result -> ...,
throwable -> ...);
Add jcenter's repository in your project's repositories list, then add the dependency.
repositories {
jcenter()
}
dependencies {
implementation 'fr.beapp.cache:cache-core:<latest-version>'
// Pick one of the following
implementation 'fr.beapp.cache:cache-storage-snappydb:<latest-version>'
implementation 'fr.beapp.cache:cache-storage-paperdb:<latest-version>'
}