Yasp

Project Url: simpleton/Yasp
Introduction: Yet Another Shared Preference
More: Author   ReportBugs   
Tags:

Download Build Status

This library try to introduce a high performance K-V store in Android development to instead of SharedPreference.

Why

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:

  1. Performance: Your data is complex or there is a lot of it
  2. Multiple thread accessing the data: invoke editor.appy() or editor.commit() multiple time, even apply will submit work to other thread.
  3. Multiple processes accessing the data: You have widgets or remote services that run in their own processes and require synchronized data

Yasp-leveldb

This library is wrapped LevelDB in java with SharedPreference interface.

Download

Use Gradle:

implementation 'com.simsun.yasp:yasp-leveldb:0.0.3'

API Usage

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.

Init

SharedPreferences sp = YASPContext.with(Context ct).getSharedPreferences(String name, int mode);

Do NOT support multiple processes currently

Get

As same as Android SharedPreference

sp.getString(String key, String defaultVal);

Editor

As same as Android SharedPreference

sp.edit()
  .putString(String key, String value)
  .putInt(String key, int value)
  .apply();

Benchmark

// TODO

Reference

  1. Best practices in Android development
  2. 请不要滥用 SharedPreference
Support Me
Apps
About Me
Google+: Trinea trinea
GitHub: Trinea