我应该保留远程数据库的本地副本吗? [英] Should i keep a local copy of remote database?

查看:84
本文介绍了我应该保留远程数据库的本地副本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个基本上允许人们创建,加入和管理其他人群的应用程序.小组中的人也可以互相发消息.

I am working on an application that will, basically, allow people to create, join and manage groups of other people. The people within the groups can also message each other.

我一直在想哪条路会更好:

I have been wondering which path would be better:

  1. 将所有信息(包括发送给用户和来自用户的消息)保留在远程数据库中.并让该应用在每次需要信息时查询服务器.甚至它以前见过的信息.
  2. 将所有信息(包括发送给用户和来自用户的消息)保留在远程数据库中.还要保留远程数据库的本地副本,并使其与远程数据库保持同步.每当应用程序需要查询信息时,它都会进行查询以查看本地表是否为最新.如果不是最新的,它将更新表并在本地表上运行查询.这样,当远程表没有更新时,它将保留本地副本,并且应用程序将具有快速查询.

  1. Keep a remote database with all the information, including messages sent to and from users. And have the app query the server every time it needs information. Even information it has seen before.
  2. Keep a remote database with all the information, including messages sent to and from users. Also keep a local copy of the remote database and just keep it synced with the remote database. Whenever the app needs to query for information, it does a query to see if the local table is up to date. If it is not up to date, it updates the table and runs the query on the local table. This way it will keep a local copy and the app will have fast queries when there is not an update to the remote table.

  • 移动应用程序和远程数据库通常会做什么?
  • 如果我只做第一名,那会是坏习惯"吗?

推荐答案

在我看来,在大多数情况下,移动设备中的数据库只是真实数据库(服务器中的一个)的缓存.因此,我的建议是将所有需要与服务器同步的数据保留在本地.这样即使在没有连接的情况下,您也可以显示信息,并在信息更新时向用户显示某些内容.

From my point of view, in most cases, the database in the mobile is just a cache of the real database, the one in the server. So, my suggestion will be to keep locally all data that you need syncing with the server. This allows you to show information even when no connection and show something to the user while the info is updated.

此外,由于这种方法将本地数据存储在服务器中,因此使它们易变而没有风险.所以:

Also, this approach makes the local data volatile without risk, as it's stored in the server. So:

  • 所有信息都在服务器中
  • 通过后台进程(服务,线程,intentservice,最适合您的服务),您可以将此信息与本地数据库同步
  • UI始终显示本地数据库中的信息

当然,这是一种非常通用的方法,需要针对每种情况进行检查,因为不同的情况可能需要不同的方法.

Of course, this is a very general approach, and needs to be examined for each case as different situations may need different approaches.

这篇关于我应该保留远程数据库的本地副本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆