一個Android SharedPreferences存儲框架:EasyCache

jopen 9年前發布 | 11K 次閱讀 EasyCache Android開發 移動開發

一個Android SharedPreferences存儲框架,基于 Java 動態代理。

Example

Step1:設置Context

public class EasyCacheApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        EasyCacheManager.getInstance().setup(this);
    }
}

Step2:代理接口:

@EasySpCache(name = "example_sp")
public interface ExampleProxy {

    @Cache
    void cacheStudent(@Key(value = "student") Student student);

    @LoadCache(key = "student",getClassType = Student.class)
    Student loadStudent();

}

Step3:存儲或讀取

Student student=new Student();
student.name="zhangsan";
student.age=18;

ExampleProxy exampleProxy= EasyCacheManager.getInstance().getCacheProxy().create(ExampleProxy.class);
//cache
exampleProxy.cacheStudent(student);
//loadCache
Student cachedStudent=exampleProxy.loadStudent();
Log.d("Student","student:"+cachedStudent.name+" "+cachedStudent.age);

項目主頁:http://www.baiduhome.net/lib/view/home/1448204405740

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!