BeApp / beapp.library.cache.android

This library provides a cache mechanism relying on RxJava.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

This library provides a cache mechanism relying on RxJava.

License:Apache License 2.0