如何将indexedDB本地数据与服务器同步? [英] How to sync indexedDB local data with Server?

查看:405
本文介绍了如何将indexedDB本地数据与服务器同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小项目,该项目在浏览器的IndexedDB中存储数据.我想添加同步功能,以便用户可以在任何地方访问数据.

I have a small project which stores data in IndexedDB in browser. I would like to add sync functionality so users can access the data everywhere.

如何在远程服务器或服务器数据库中同步本地IndexedDB数据,以便可以在任何地方访问它?换句话说,我想让此演示在我所有的产品中都可用浏览器. (在此阶段,安全性不是问题)

How can I sync local IndexedDB data in a remote server or server database so I can access it everywhere? In other words, I would like to make this demo available in all of my browsers. (Security is not a problem in this phase)

推荐答案

实际上,IndexedDB上没有太多用于同步数据库的内容.您只需 RESTful 服务,即可从服务器复制到客户端,反之亦然.

In fact, there is not much on IndexedDB for synchronising database. You only need RESTful service for replicating from server to client and vice versa.

为实现有效的同步,该服务应为每个记录支持etag(HTTP规范),并为集合更新(ATOM规范).另外,为了支持可恢复的更新,totalResults,startIndex,itemsPerPage( OpenSearch 规范)和按更新顺序排序是必要的.

For effective synchronization, the service should support etag (HTTP spec) for each record, updated (ATOM spec) for collections. Additionally to support resumable update, totalResults, startIndex, itemsPerPage (OpenSearch spec) and ordering by updated is necessary.

当获取etag的记录'If-None-Match'标头时,为了获得完整的缓存利益,当指定记录'If-Match'头标时,可以解决客户端的冲突.为了更新集合,查询受到更新参数的限制,因此仅返回不在客户端数据库中的记录.

When GETting a record 'If-None-Match' header of etag is specified, to get full caching benefit, When PUTting a record 'If-Match' header is specified to resolve conflict on client side. To update the collection, query is limited by updated parameter, so that only records not in the client database are returned.

这就是我参加在开源IndexedDB API包装器上实现的方式.请参阅angularjs中的示例应用程序 https://github.com/yathit/feature-matrix

That is how I attend to implement on my open source IndexedDB API wrapper. See example app https://github.com/yathit/feature-matrix in angularjs and demo.

还要查看 PouchDB .

这篇关于如何将indexedDB本地数据与服务器同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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