anupcowkur / reservoir Goto Github PK
View Code? Open in Web Editor NEWAndroid library to easily serialize and cache your objects to disk using key/value pairs.
License: MIT License
Android library to easily serialize and cache your objects to disk using key/value pairs.
License: MIT License
Hi,
this is already a nice implementation for a cache. But I have a feature request:
It would be nice to be able to specify an expiration time. When getting an item from the cache it would first check if the item exists and if it is expired. A Method should be passed to the get-request which will be executed to retrieve the new items which will be saved to cache after returning.
-> Observable rxObject = cache.get(, <FETCH_DATA>, <MAX_AGE>)
T: The type of the item
KEY: The key of the item
FETCH_DATA: A class that returns a list of T or a single T which is executed asynchronously
That's just a raw idea... but it would be very nice.
best regards
Tobias
Can add the option to delete a value by key?
I think it would be easy for you
If not I can't use the library ;)
Thanks,
How to invalidate cache when the app updates to a new version?
I really love using this library.
Is there any chance to make it for iOS Swift3 ? :)
Thank you again
I am planning to use this library to store Hash. The size of the Hash may he up to 10,000 or even more.
Can this library used to store Hash?
Also what can be the possible causes for the failure of storing any object?
Any help would be really Grateful.
Hello! I've got a strange NPE in Reservoir.get()
method:
java.lang.NullPointerException
at com.anupcowkur.reservoir.Reservoir.get(Reservoir.java:75)
...
How is it possible if I always check a key and a value for null before saving in the Reservoir?
Hi,
I added Reservoir to my project where I already use rxJava2. So I try to add Reservoir as dependency without rxJava reference.
Into my gradle file I have only:
compile 'com.anupcowkur:reservoir:3.1.0'
but I give this error:
Rejecting re-init on previously-failed class java.lang.Class<com.anupcowkur.reservoir.Reservoir$1>: java.lang.NoClassDefFoundError: Failed resolution of: Lrx/Observable$OnSubscribe;
I don't really want to add rxJava1 dependency to avoid a mess with rxJava2 imports.
Any suggestions?
Currently RxAndroid is added as a 'compile' dependency in the library, this can be an overhead (it adds around 3555 methods to the overall method count) to projects and upstream libraries which do not use RxAndroid. Can we offer the RxJava dependency as a 'provided' dependency to work around this?
I'm also adding a Pull Request for reference, all the Espresso seem to pass.
Loving the functionality of this library, but the fact that you're including the dependencies as .jar files as opposed to proper dependencies in your .pom or build.gradle is resulting in errors like;
com.android.dex.DexException: Multiple dex files define Lcom/jakewharton/disklrucache/DiskLruCache$1;
You should switch to loading dependencies through
compile 'com.jakewharton:disklrucache:2.0.2'
compile 'com.google.code.gson:gson:2.2.2'
compile 'commons-io:commons-io:2.4'
I think this library should use getCacheDir() for disk cache storage, because it stores temprorary data and not user documents.
http://developer.android.com/reference/android/content/Context.html#getCacheDir()
I think this library should not be initialized via static method, because it prevents creating multiple reservoirs and using it in different libraries.
saving and restoring objects to and from disk using RxJava on Android will be more awesome ! like (https://github.com/Naturally-Being/G-Rex)
It would be nice to add an option to delete everything.
this does not happen to putAsync
. This only happens to getAsync
.
My code:
final Type resultType = new TypeToken<List<Category>>() {
}.getType();
Reservoir.getAsync("categories", resultType, new ReservoirGetCallback<List<Category>>() {
@Override
public void onSuccess(List<Category> categories) {
//success
Log.i(TAG, "onSuccess");
}
@Override
public void onFailure(Exception e) {
//error
Log.e(TAG, "onFailure", e);
fetchCatsFromRemote(object);
}
});
I was using your library in a project but then I started using retrofit and recently came across this post http://blog.denevell.org/android-okhttp-retrofit-using-cache.html , which implies okhttp response cache can be used along with retrofit to cache network requests and use them offline.
So can you highlight how reservoir is different than the above solution or can be it be used with retrofit in a better way. My use case is simple, I'm getting data from rest api using retrofit but the data changes rarely like once in a week. So which solution would work best for me?
I don't understand this error, the piece below logs the error
Reservoir.getAsync("eventsData", resultType, new ReservoirGetCallback<List<EventsDataList>>(){
@Override
public void onSuccess(List<EventsDataList> events) {
//success
mAdapter.addAll(events);
}
@Override
public void onFailure(Exception e) {
//error
Log.d("ErrorLog", e.getMessage()); //This is where i get the error
}
});
HI,
When compiling my project with your library, Android studio compares the manifests between the project and the library and if it finds an icon or label property in the library, it complaints and doesn't want to compile, as you can see below.
Can you modify and remove this parameters and release another version?
Thanks.
/** is also present at com.github.anupcowkur:reservoir:1.1.1:6:45 value=(@drawable/ic_launcher)
Suggestion: add 'tools:replace="icon"' to element at AndroidManifest.xml:34:5 to override
C:\Users\druidamix\saton\saton\src\main\AndroidManifest.xml
Error:(39, 9) Attribute application@icon value=(@drawable/saton) from AndroidManifest.xml:39:9
Error:(38, 9) Attribute application@label value=(SATON) from AndroidManifest.xml:38:9
is also present at com.github.anupcowkur:reservoir:1.1.1:6:82 value=(@string/app_name)
Suggestion: add 'tools:replace="label"' to element at AndroidManifest.xml:34:5 to override
Error:Execution failed for task ':saton:processDebugManifest'.
Manifest merger failed with multiple errors, see logs
Information:BUILD FAILED **/
Request : Support for expiry policy for cached objects
In the current implementation, performing an operation without calling init leads to an NullPointerException without specifying the cause. This should be made more explicit.
Hi, i'm trying to use reservoir with an object extending another object but it gives me a 'NullpointerException' when i'm trying to get it from cache. So, is it a bug or it doesn't work with this kind of objects?
can you make GetTask public, so that we could be able to cancel getAsync or putAsync
Thanks for the great library, and here what I am getting
Attempt to invoke virtual method 'java.lang.String com.anupcowkur.reservoir.SimpleDiskCache$StringEntry.getString()' on a null object reference
Any help please?
One of my customers is frequently seeing the following issue in a beta version of their app. We've seen over 60+ non-fatals over 3 separate instances affecting 10+ users in a beta test group of around 15
Trace:
java.lang.NullPointerException
at com.anupcowkur.reservoir.Reservoir$GetTask.doInBackground(Reservoir.java:180)
at com.anupcowkur.reservoir.Reservoir$GetTask.doInBackground(Reservoir.java:163)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
This happens at multiple locations in the app and has no specific trigger. Reservoir has been initiated in the application object like so:
Reservoir.init(this, 100000);
Seems the cache object might be null in Reservoir.java:180, let me know if you need any more information to reproduce the issue
RxJava 1 has reached end of life. Time to move to RxJava 2.
Or am I supposed to handle it myself?
this project support multiprocess operation ?
I get this GSON error when using Reservoir.get
.
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 2 path $
08-16 22:26:38.087 18657-18944/ca.jeffrey.apodgallery W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224)
08-16 22:26:38.087 18657-18944/ca.jeffrey.apodgallery W/System.err: at com.google.gson.Gson.fromJson(Gson.java:887)
08-16 22:26:38.087 18657-18944/ca.jeffrey.apodgallery W/System.err: at com.google.gson.Gson.fromJson(Gson.java:852)
08-16 22:26:38.087 18657-18944/ca.jeffrey.apodgallery W/System.err: at com.google.gson.Gson.fromJson(Gson.java:801)
08-16 22:26:38.087 18657-18944/ca.jeffrey.apodgallery W/System.err: at com.google.gson.Gson.fromJson(Gson.java:773)
08-16 22:26:38.087 18657-18944/ca.jeffrey.apodgallery W/System.err: at com.anupcowkur.reservoir.Reservoir.get(Reservoir.java:176)
What Proguard Rules should I put in my proguard-rules.pro
file?
When i try to run my project with your library i got this error every time:
Error:Execution failed for task ':mobile:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
This is my Gradle dependencies:
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.google.code.findbugs:annotations:3.0.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.github.androidquery:androidquery:0.26.9'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'org.androidannotations:androidannotations-api:3.2'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile "com.daimajia.swipelayout:library:1.2.0@aar"
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.squareup.okhttp:okhttp:2.4.0'
// compile 'com.anupcowkur:reservoir:2.0'
// Design Support Library
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:design:22.2.0'
method bytesUsed() does not has a public access, should provide public access.
The link to download standalone jar returns 404 https://github.com/anupcowkur/Reservoir/releases/download/v1.1/reservoir-1.1.1.jar
I have a strange behavior. I have called WS with okhttp + retrofit and I have retrieved POJO. Then I want save these objects with Reservoir. My method putReservoir
goes in onSuccess but getReservoir
goes in onFailure. In both side, I'm using the same object.
As a consequence, I have another question ==> Where are data on the phone ?
I want to cache the data with multiple keys and retrieve them. Like for example, first I want to save some data with key A and after that some data with key B and so on. And then retrieve that data based on the keys. Is that possible??
I'm having some issues caching a list of objects. Apparently I'm not passing the correct Class
to the Reservoir.get
method when deserializing the list. I have confirmed that the write works just fine, and the Json is in the cache file.
I tried a few things that i would normally do when using Gson:
// In Gson
Type type = new TypeToken<List<MyObject>>() {}.getType());
List<MyObject> objects = gson.fromJson( jsonString, type );
// In Reservoir
Class clazz = new TypeToken<List<MyObject>>() {}.getType()).getClass();
List<MyObject> objects = Reservoir.get( "myKey", clazz );
As you can imagine the above doesn't work.
After trying a few other things, I noticed that while Gson api exposes the following methods:
public <T> T fromJson(String json, Class<T> classOfT)
public <T> T fromJson(String json, Type typeOfT)
But reservoir only exposes
public <T> T fromJson(String json, Class<T> classOfT)
Would it be worth to overload the methods in the library to take Type
s too?
Does anyone knows a workaround that doesn't involved wrapping the list in another object ?
Thanks
I think this library should allow to use LruCache as front-end memory cache before DiskLruCache.
I don't know if I did something wrong with the library, but I've got a new crash report from a user. Could you check it?
The stack trace:
java.lang.NullPointerException
at com.anupcowkur.reservoir.SimpleDiskCache.writeMetadata(SimpleDiskCache.java:108)
at com.anupcowkur.reservoir.SimpleDiskCache.openStream(SimpleDiskCache.java:73)
at com.anupcowkur.reservoir.SimpleDiskCache.put(SimpleDiskCache.java:95)
at com.anupcowkur.reservoir.SimpleDiskCache.put(SimpleDiskCache.java:83)
at com.anupcowkur.reservoir.Reservoir.put(Reservoir.java:47)
...
The problem is kinda weird. When I try to store objects that have ID variables inside, I face this exception:
java.lang.IllegalArgumentException: class xxxxx.Article declares multiple JSON fields named id .....
How to solve this problem?
Hi,
To make it work I had to put UTF-8 in value.getBytes, since in my language I use accents. If the charsetname is not defined the result string of getbytes can be chopped
Cheers.
private void put(String key, String value, Map<String, ? extends Serializable> annotations)
throws
IOException {
OutputStream cos = null;
try {
cos = openStream(key, annotations);
cos.write(value.getBytes(HTTP.UTF_8));
} finally {
if (cos != null)
cos.close();
}
}
Due to this issue https://code.google.com/p/android/issues/detail?id=70073 and the fact the the reservoir library explicitly sets allowBackup to true, I can't set allowBackup to false.
Can allowBackup=true be removed from the manifest?
Hi Guys, I getting this issue with the lib
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x81bb2c25 in tid 27598
do you know whats the cause?
Regards
Reservoir.put("lol", "fsdfasdfa");
Reservoir.delete("lol");
Reservoir.contains("lol") returns true
Reservoir.put("lol", "fsdfasdfa");
Reservoir.clear()
Reservoir.contains("lol") returns false
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.