46 lines
1.0 KiB
Plaintext
Executable File
46 lines
1.0 KiB
Plaintext
Executable File
package com.example.administrator.ximengjianyu.utils;
|
|
|
|
import android.content.Context;
|
|
|
|
/**
|
|
* 网络缓存工具类
|
|
*/
|
|
public class CacheUtils {
|
|
|
|
/**
|
|
* 写缓存
|
|
* 以url为key(标识),以json为值, 保存在本地sp
|
|
*/
|
|
public static void setCache(Context ctx, String key, String json) {
|
|
//有时也会保存在本地文件中, 以MD5(url)为文件名,以json为文件内容保存在sdcard中
|
|
PrefUtils.putString(ctx, key, json);
|
|
}
|
|
|
|
/**读缓存
|
|
* 从本地sp中
|
|
* @param ctx
|
|
* @param key
|
|
* @return
|
|
*/
|
|
public static String getCache(Context ctx, String key) {
|
|
|
|
|
|
//读MD5(url)文件名
|
|
return PrefUtils.getString(ctx, key, null);
|
|
}
|
|
|
|
/**
|
|
* 清空本地sp
|
|
* @param ctx
|
|
*/
|
|
public static void clearPre(Context ctx){
|
|
PrefUtils.clearPre(ctx);
|
|
}
|
|
|
|
public static void removePro(Context ctx, String key){
|
|
PrefUtils.removePre(ctx,key);
|
|
}
|
|
|
|
|
|
}
|