本文介绍了缓存下载的JSON数据,SQLite数据库 - 它是一个好主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序我必须从众多的Web服务下载JSON数据。我使用的数据类是相当复杂的(很多属性,相当深继承树等)。

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

我打算做缓存,使用单个数据库表,在那里我会存储在VARCHAR列下载的JSON数据(以及包含列其他元数据)。 JSON序列化正在做的GSON库。

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.

这似乎只是倾倒的情况下为JSON,并再次解析它们后,当我需要他们挺方便的。无需为每个类创建自定义的表,或者写的自定义序列化code加载。另外,我可以在高速缓存表做查询这个样子。

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?

推荐答案

是绝对没有错的方法;不过,我会建议您改为使用内置的高速缓冲存储器。见一节保存缓存文件的数据存储了解details.This方式你不养猪任何precious空间,如果你的JSON对象是大的内存不足的情况​​时。

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.

这篇关于缓存下载的JSON数据,SQLite数据库 - 它是一个好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 14:12