Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caching downloaded JSON data to SQLite database - is it a good idea?

In my app I have to download JSON data from numerous web services. The data classes I use are fairly complex ones (lots of properties, quite deep inheritance tree, etc.).

I intend to do caching, using a single db table, where I'd store the downloaded JSON data in a VARCHAR column (along with other meta-data containing columns). JSON serialization is being done with the Gson library.

It seems quite convenient to just dump the instances into JSON, and parse them again later when I need them. No need to create custom tables for every class, or write loads of custom serialization code. Also, I can do queries on the cache table this way.

The question: Is this approach an anti-pattern by any means?

like image 775
Zsombor Erdődy-Nagy Avatar asked Mar 27 '11 15:03

Zsombor Erdődy-Nagy


1 Answers

There is absolutely nothing wrong with this approach; however, I am going to recommend that you instead use the built in caching storage. See the section called "Saving cache files" in Data Storage for more details.This way you don't hog any precious space if your JSON objects are large in the event of a low memory situation.

like image 178
Andrew White Avatar answered Sep 25 '22 12:09

Andrew White