This library try to introduce a high performance K-V store in Android development to instead of SharedPreference.
If you only need to persist simple values and your application runs in a single process SharedPreferences is probably enough for you. It is a good default option.
There are some situations where SharedPreferences are not suitable for store KV data:
- Performance: Your data is complex or there is a lot of it
- Multiple thread accessing the data: invoke
editor.appy()
oreditor.commit()
multiple time, evenapply
will submit work to other thread. - Multiple processes accessing the data: You have widgets or remote services that run in their own processes and require synchronized data
This library is wrapped LevelDB in java with SharedPreference interface.
Use Gradle:
implementation 'com.simsun.yasp:yasp-leveldb:0.0.3'
Almost compat with Android SharedPreference, but there is a little different during initializing.
Yasp will NOT load whole file when you access one parameter. Feel free to cache yasp instance in your Application.
SharedPreferences sp = YASPContext.with(Context ct).getSharedPreferences(String name, int mode);
Do NOT support multiple processes currently
As same as Android SharedPreference
sp.getString(String key, String defaultVal);
As same as Android SharedPreference
sp.edit()
.putString(String key, String value)
.putInt(String key, int value)
.apply();
// TODO