RxSnappy

Additional

Language
Java
Version
N/A
Created
Nov 30, 2015
Updated
Sep 15, 2016 (Retired)
Owner
Supercharge (team-supercharge)
Contributors
Richard Radics (richardradics)
Paco (pakoito)
2
Activity
Badge
Generate
Download
Source code

#RxSnappy

RxSnappy is a thread safe rxjava wrapper for the great SnappyDB fast key-value database for Android.

This library offers a time based raw response cache solution on client side.

Usage

  • Get artifact
compile 'io.supercharge:rxsnappy:0.4.0'
  • In application's onCreate() call
RxSnappy.init(context);
  • Create RxSnappyClient
RxSnappyClient rxSnappyClient = new RxSnappyClient();

rxSnappyClient.setObject(key, object).subscribe(object -> ...);

rxSnappyClient.getObject(key, Object.class).subscribe(object -> ...);
  • Every record automatically gets an id which id is the date in milliseconds of the insertion
public Observable<FooResponse> getFooResponse(String token, BarRequest barRequest){

//Generate unique key 
final String key = RxSnappyUtils.generateKey("fooresponse", token, barRequest);

//Look for in cache with a time interval (ms)
//If the data in cache is older than 15 sec it throws an exception
return rxSnappyClient.getObject(key, 15000L, FooResponse.class)
 .onErrorResumeNext(retrofitApi.getFooResponse(token, barRequest)
  .flatMap(fooResponse -> rxSnappyClient.setObject(key, fooResponse));
}

Contributing

Please fork this repository and create a pull request Any contributions, large or small, major features, bug fixes, unit tests are welcomed and appreciated but will be thoroughly reviewed and discussed.

Run the instumentation tests before PR!

License

RxSnappy is opensource, contribution and feedback are welcomed

Apache Version 2.0

Copyright 2015 Supercharge

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Author

richardradics