Package Com.innjoo.store.cache;import Com.ferris.utils.stringutils;import android.support.v4.util.lrucache;/** * * @ Classname:lrujsoncache JSON Cache class * @Description: TODO * @author Replay * @email [email protected] * @date 2014-12-27 PM 5:3 3:49 * @csdn Blog.csdn.net/xufeifandj */public class Lrujsoncache {private lrucache<string, string> MMemoryCache; Public Lrujsoncache () {int maxmemory = (int) runtime.getruntime (). MaxMemory ()/10;mmemorycache = new lrucache<string, String> (maxmemory) {@Overrideprotected int sizeOf (string key, String value) {return value.length ();}}; /** * * @Title: Addjsontomemorycache * @Description: TODO add JSON memory * @return void */public void Addjsontomemorycache (stri Ng key, String jsonstring) {if (Mmemorycache = = null) {return;} if (Stringutils.isempty (key)) {return;} if (Getjsonfrommemcache (key) = = NULL && jsonstring! = null) {Mmemorycache.put (key, jsonstring);}} /** * Gets a JSON from the memory cache * @param key * @return */public String Getjsonfrommemcache (strinG key) {if (Mmemorycache = = null) {return null;} return Mmemorycache.get (key);}}
Android HTTP request JSON data cache to memory