设置缓存工具

 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);

posted on 2016-06-14 19:36  oooo呼呼  阅读(246)  评论(0编辑  收藏  举报