简体   繁体   English

将JSON数据存储为平面文件或数据库中

[英]Storing JSON data as Flat file or in Database

I am fetching JSON data from the web and I am confuse on which is the best and faster way to store and retrieve JSON. 我正在从Web上获取JSON数据,但我感到困惑的是,哪种方法是存储和检索JSON的最佳,最快方法。 Since I am not I am not handling complex queries. 由于我不是,所以我不处理复杂的查询。 Is it advisable to store as flat file data.json or it should be in the database? 建议将其存储为平面文件data.json还是应将其存储在数据库中?

BTW, I am using PHP. 顺便说一句,我正在使用PHP。

It depends on the size of the data and the frequency of access. 它取决于数据的大小和访问的频率。 Not sure about MySql, but Postgres of late has excellent json-processing capabilities, allowing you to query or even index directly into your json data. 不确定MySql,但最近的Postgres具有出色的json处理功能,可以让您查询甚至直接建立json数据索引。 This is definitely the way to go if your documents are several kilobytes at most or have almost constant size to keep the storage engine happy. 如果您的文档最大为几千字节或具有几乎恒定的大小以使存储引擎满意,那么这绝对是可行的方法。

For large objects it's better to stick to the filesystem, storing a brief of the document in the DB to allow fast operations on most important fields. 对于大型对象,最好坚持使用文件系统,将简短的文档存储在数据库中,以允许对最重要的字段进行快速操作。

edit : since the data will be frequently replaced, it is best to avoid disk writes and use a fast though less-reliable RAM-only storage like Redis. 编辑 :由于数据将被频繁替换,因此最好避免磁盘写入,并使用快速但不太可靠的纯RAM存储(如Redis)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM