Git Product home page Git Product logo

reservoir's Introduction

Reservoir

Reservoir is a simple library for Android that allows you to easily serialize and persist your objects on disk using key/value pairs.

Usage

Initialize

Reservoir uses the internal storage allocated to your app. Before you can do anything, you need to initialize Reservoir with the cache size.

try {
    Reservoir.init(this, 2048); //in bytes
} catch (Exception e) {
        //failure
}

The best place to do this would be in your application's onCreate() method.

Since this library depends directly on DiskLruCache, you can refer that project for more info on the maximum size you can allocate etc.

Put stuff

You can put objects into Reservoir synchronously or asynchronously.

Async put will you give you a callback on completion:

Reservoir.putAsync("myKey", myObject, new ReservoirPutCallback() {
            @Override
            public void onSuccess() {
                //success
            }

            @Override
            public void onFailure(Exception e) {
                //error
            }
        });

synchronous put:

try {
    Reservoir.put("myKey",myObject);
} catch (Exception e) {
    //failure;
}

Async put uses the standard AsyncTask provided by the Android framework.

Get Stuff

You can get stuff out of Reservoir synchronously or asynchronously as well.

Async get will give you a callback on completion:

Reservoir.getAsync("myKey", MyClass.class, new ReservoirGetCallback<MyClass>() {
            @Override
            public void onSuccess(MyClass myObject) {
                //success
            }

            @Override
            public void onFailure(Exception e) {
                //error
            }
        });

synchronous get:

try {
    Reservoir.get("myKey",MyClass.class);
} catch (Exception e) {
        //failure
}

Check for existence

If you wish to know whether an object exists for the given key, you can use:

try {
    boolean objectExists = Reservoir.contains("myKey");
} catch (Exception e) {}

Including in your project

You can directly download the jar and add it to your project. You will also need to add the jars on which Reservoir depends i.e. DiskLruCache, Apache Commons IO and GSON.

If you use Maven:

<dependency>
  <groupId>com.github.anupcowkur</groupId>
  <artifactId>reservoir</artifactId>
  <version>1.1.1</version>
</dependency>

or Gradle:

compile 'com.github.anupcowkur:reservoir:1.1.1'

Sample

Check out the sample application for example of typical usage.

Contributing

Contributions welcome via Github pull requests.

Credits

Reservoir is just a tiny little convenience wrapper around the following fantastic projects:

Thanks, you guys!

License

This project is licensed under the MIT License. Please refer the License.txt file.

reservoir's People

Contributors

anupcowkur avatar trevor-e avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.