Skip to content

BeApp/beapp.library.cache.android

Repository files navigation

This library provides a cache mechanism relying on RxJava. There are currently two storage implementation :

Usage

Two steps are needed :

  1. Prepare an instance of your storage implementation
  2. Declare an instance of RxCache with the storage implementation
  3. 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 -> ...);

Installation

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>'
}