An Android library to cache any serializable objects to disk, using a LRU cache implementation, with the possibility to specify an expiry time for each entry and a maximum size that can be allocated.
Java
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
gradle/wrapper
library
.gitignore
.travis.yml
README.md
build.gradle
gradlew
gradlew.bat
settings.gradle

README.md

Storo

Storo

Build Status Android Arsenal

An Android library to cache any serializable objects to disk, using a LRU cache implementation, with the possibility to specify an expiry time for each entry and a maximum size that can be allocated.

How to use

Integrate the library in your project

Add the JitPack repository to your project's build.gradle file:

repositores {
    maven { url 'https://jitpack.io' }
}

And then add the following line into the 'dependencies' block:

compile('com.github.lowlevel-studios:storo:1.2.0') {
    transitive = true
}

Initialize Storo

StoroBuilder.configure(8192)  // maximum size to allocate in bytes
    .setDefaultCacheDirectory(this)
    .initialize();

Put an object

Storo.put("key", object).execute();  // store object without an expiry
Storo.put("key", object).setExpiry(2, TimeUnit.HOURS).execute();  // store object with an expiry of 2 hours

Get an object

MyObject object = Storo.get("key", MyObject.class).execute();

Delete an object

boolean result = Storo.delete("key");

Check if an object exists

boolean result = Storo.contains("key");

Check if an object has expired

Boolean result = Storo.hasExpired("key").execute();   // null if the object does not exist

Get the object count

int count = Storo.count();

Clear the entire cache

boolean result = Storo.clear();

Async calls

Storo.put("key", object, ...).async(new Callback<Boolean>);
Storo.get("key", MyObject.class).async(new Callback<MyObject>);
Storo.hasExpired("key").async(new Callback<Boolean>);

RxJava (1.x and 2.x) support

This library provides two helper classes (RxStoro and RxStoro2, for RxJava 1.x and 2.x respectively) that can be used to obtain a Single<T> that will execute the passed method.

// RxJava 1.x
RxStoro.with(Storo.put("key", object, ....)).subscribe(...);  // this will be scheduled on the caller thread

// RxJava 2.x
RxStoro2.async(Storo.get("key", MyObject.class)).subscribe(...);  // this will be scheduled on a background thread and observed on the main thread

License

Copyright 2017 Lowlevel Studios

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.