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.
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
}
StoroBuilder.configure(8192) // maximum size to allocate in bytes
.setDefaultCacheDirectory(this)
.initialize();
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
MyObject object = Storo.get("key", MyObject.class).execute();
boolean result = Storo.delete("key");
boolean result = Storo.contains("key");
Boolean result = Storo.hasExpired("key").execute(); // null if the object does not exist
int count = Storo.count();
boolean result = Storo.clear();
Storo.put("key", object, ...).async(new Callback<Boolean>);
Storo.get("key", MyObject.class).async(new Callback<MyObject>);
Storo.hasExpired("key").async(new Callback<Boolean>);
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
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.