package com.example.cache; import android.content.Context; import android.content.SharedPreferences; /** * Created by Administrator on 2016/3/6. */ public class JsonCache { private static JsonCache jsonCache = null; public static final String NAME = "com.crazy.gemi.ui.utils.JsonCache"; private SharedPreferences preferences; private static Context context; private JsonCache(Context context){ this.context = context; preferences = context.getSharedPreferences(NAME, 0); } public static JsonCache getInstance(Context context){ if (jsonCache == null) { jsonCache = new JsonCache(context); } return jsonCache; } public void setJsonCache(String key, String value){ preferences.edit().putString(key, value).commit(); } public String getJsonCache(String key){ return preferences.getString(key, null); } public void clearCache() { preferences.edit().clear().commit(); } public void removeCache(String key){ preferences.edit().remove(key).commit(); } }
安卓简单缓存类(单例模式)
最新推荐文章于 2024-04-28 08:43:59 发布