网络缓存工具

来源:互联网 发布:宠物商城源码 编辑:程序博客网 时间:2024/06/08 05:50
/** * 网络缓存工具 */public class CacheUtils {    //写缓存    public static void setCache(Context ctx ,String url,String json){        PrefUtils.putString(ctx,url,json);    }    //读缓存    public static String getCache(Context ctx , String url){        return PrefUtils.getString(ctx,url,null);    }}

/** * 专门访问和设置SharePreference的工具类, 保存和配置一些设置信息 *  * @author Kevin *  */public class PrefUtils {    private static final String SHARE_PREFS_NAME = "itcast";    public static void putBoolean(Context ctx, String key, boolean value) {        SharedPreferences pref = ctx.getSharedPreferences(SHARE_PREFS_NAME,                Context.MODE_PRIVATE);        pref.edit().putBoolean(key, value).commit();    }    public static boolean getBoolean(Context ctx, String key,            boolean defaultValue) {        SharedPreferences pref = ctx.getSharedPreferences(SHARE_PREFS_NAME,                Context.MODE_PRIVATE);        return pref.getBoolean(key, defaultValue);    }    public static void putString(Context ctx, String key, String value) {        SharedPreferences pref = ctx.getSharedPreferences(SHARE_PREFS_NAME,                Context.MODE_PRIVATE);        pref.edit().putString(key, value).commit();    }    public static String getString(Context ctx, String key, String defaultValue) {        SharedPreferences pref = ctx.getSharedPreferences(SHARE_PREFS_NAME,                Context.MODE_PRIVATE);        return pref.getString(key, defaultValue);    }    public static void putInt(Context ctx, String key, int value) {        SharedPreferences pref = ctx.getSharedPreferences(SHARE_PREFS_NAME,                Context.MODE_PRIVATE);        pref.edit().putInt(key, value).commit();    }    public static int getInt(Context ctx, String key, int defaultValue) {        SharedPreferences pref = ctx.getSharedPreferences(SHARE_PREFS_NAME,                Context.MODE_PRIVATE);        return pref.getInt(key, defaultValue);    }}

下载 地址 :

http://download.csdn.net/detail/q9104422999/9701529

0 0
原创粉丝点击