1 public class CacheUtils {
2 /**
3 *
4 * 设置缓存
5 * @param key url
6 * @param value json
7 * @param context
8 */
9 public static void setcache(String key,String value,Context context){
10 SharePrefersUtils.setstring(context, key, value);
11 }
12
13 /**
14 *
15 * 获取缓存
16 */
17 public static String getcache(String key,Context context){
18 return SharePrefersUtils.getstring(context, key,
null);
19 }
20
21
22 }
运用:
// 获取数据 String cache = CacheUtils.getcache(murl, mactivity); if (!TextUtils.isEmpty(cache)) {// 如果缓存存在,则直接解析,无需访问网络 ParseNewsdetailData(cache, false); }
设置缓存:CacheUtils.setcache(murl, result, mactivity);
转载于:https://www.cnblogs.com/wangying222/p/5585268.html