Caching downloaded JSON data to SQLite database - is it a good idea?
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.
Related videos on Youtube
Zsombor Erdődy-Nagy
C++, Java, Android developer. MSc in software engineering. Employed as engineer manager at Uber, Amsterdam. http://hu.linkedin.com/in/rzsombor https://github.com/rzsombor
Updated on March 28, 2020Comments
-
Zsombor Erdődy-Nagy about 4 years
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?
-
Matthew Willis about 13 yearsIt does seem strange to use a sqlite db as a file store--why not wait until you're ready to store the structured data represented by your json?
-