Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best way to caching json

My application should work not only in online but also in offline mode. For that reason I am considering find the best way for cashing data. I't like use SharedPreference for store data but in android documentation writen Maximum size in characters allowed for a preferences value is 8192. I don't know this is ok or not? I tried to pass out of this idea trying to use FileCashing or sqLite cashing.

So what you think guys what is the best SharedPreference vs FileCashing or vs SqLiteCaching?

like image 542
fish40 Avatar asked Aug 29 '13 08:08

fish40


People also ask

How do I cache JSON data?

In order to add data in cache as JSON, the objects need to be created according to the JSON standards provided by NCache. JsonObject is added in the cache against a unique key. This key will be used to perform further operations on the cache.

Can we store JSON in Redis?

RedisJSON stores the data in a binary format which removes the storage overhead from JSON, provides quicker access to elements without de-/re-serialization times. To use RedisJSON you need to install it in your Redis server or enable it in your Redis Enterprise database.

Is JSON a good way to store data?

JSON is perfect for storing temporary data. For example, temporary data can be user-generated data, such as a submitted form on a website. JSON can also be used as a data format for any programming language to provide a high level of interoperability.

Do browsers cache JSON?

Yes. Caching related headers and (how they are handled) work for all HTTP resources.


1 Answers

Save the json in cache directory as file....

Save:

// Instantiate a JSON object from the request response
JSONObject jsonObject = new JSONObject(json);
// Save the JSONOvject
ObjectOutput out = new ObjectOutputStream(new FileOutputStream(new File(getCacheDir(),"")+"cacheFile.srl"));
out.writeObject( jsonObject );
out.close();

Retrieve:

// Load in an object
ObjectInputStream in = new ObjectInputStream(new FileInputStream(new File(new File(getCacheDir(),"")+"cacheFile.srl")));
JSONObject jsonObject = (JSONObject) in.readObject();
in.close();
like image 188
fida1989 Avatar answered Sep 24 '22 21:09

fida1989