Chrome.Storage.Local持久性 [英] Chrome.Storage.Local Persistence

查看:330
本文介绍了Chrome.Storage.Local持久性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有。我已经开始使用Chrome的各种API开发小型扩展,尽管事情非常好,但我仍然对好几件事感到好奇。

如果你们全都问不介意帮助我:



1。有人能告诉我chrome.storage.local的持久性有什么限制吗?我自己尝试了各种测试,比如用chrome.storage.local.set()存储一些东西,清除我所有的浏览器历史记录,cookies等等,然后看看是否所有东西都还在那里。通常情况下它仍然会在那里,但有时候我会稍后再回来看看,它会消失的。总的来说,我一直无法明确标示我正在做什么,偶尔会清除.local数据。

目前为止主要通过chrome.storage.sync工作,所有同时使用Chrome的登录到Chrome功能登录 。我在API页面上阅读,在Chrome离线时使用.sync(以及未登录,我假设,这是我的情况),数据存储在本地,然后再同步。我主要关心的是这是否意味着我使用chrome.storage.sync存储的数据可能会被删除,因为我使用chrome.storage.local存储的数据在过去有吗?我一直在使用.sync的一个主要原因是因为我从来没有过使用.local擦除数据的经验,而我使用.local(正如我在#1中所描述的那样)。



非常感谢!请帮助我!



编辑:我很确定.local清除不会发生,因为我错误地删除了扩展名然后将其添加回来。我知道 会清除.local数据(但保留.sync)。

解决方案

我是该API的作者。



chrome.storage.local不应该在卸载时消失(听起来像是您的),或者很少发生数据库损坏(我们已经看到了这种情况在系统还原中出现)。



chrome.storage.sync的工作方式相同,除了如果两台机器发生冲突的更改,则它使用的合并算法可能会导致数据丢失。在你的情况下,如果你登录使用chrome.storage.sync的机器,可能会发生这种情况。更常见的情况是,因为一台机器在进行更改时处于脱机状态,或者用户可能设法同时在两台机器上更改数据(这就是为什么建议仅更改用户操作的数据 - 我们应该记录该数据)。 p>

对于它的价值 - 我们也应该记录它 - 合并算法是last-change-wins和sync-is-source-of-truth - 但任何本地键/值对添加将不会被删除。如果您在计算机A(登录并同步)中有

{a:1,b:2},则
{b:3,c:4 }在计算机B上(未登录),

和计算机B登录后,完成同步后,A和B上的存储状态将以{ a:1,b:2,c:4},因为A的数据已经是同步的一部分,这是真相的来源,但是'c'还没有存在,因此被添加了。

在这种情况下,A将获得一个添加'c'的onChange事件,并且B将获得一个onChange事件,添加'a'并将'b'从3更新为2。


all. I've started developing small extensions using Chrome's various API's, and although things are working great, I'm still curious about a few things.

Two questions, if you all wouldn't mind helping me out:

1. Could someone tell me what the limits are to chrome.storage.local's persistence? I've tried various tests on my own, such as storing a few things with chrome.storage.local.set(), clearing all of my browser history, cookies, etc. and then seeing if everything is still there. Often it will still be there, but sometimes I'll check back later and it will be gone. Overall, I have been unable to definitively label what I'm doing that is occasionally clearing the .local data.

2. I've been working mostly with chrome.storage.sync so far, all while not being signed in using Chrome's "Sign in to Chrome" feature. I read on the API page that in the case that .sync is used while Chrome is offline (as well as not logged in, I'm assuming, which is my case), data is stored locally and then sync'ed later on. My main concern is does this mean the data I'm storing using chrome.storage.sync could potentially get erased as the data I'm storing using chrome.storage.local has in the past? One of the main reasons I've been using .sync anyway is because I've never had an experience of data getting erased with it, while I have with .local (as I've described in #1).

Thanks so much! Help me out, please!

Edit: I'm pretty sure the .local clear isn't happening because of me mistakenly removing the extension and then adding it back in. I know that that will clear the .local data (but preserve the .sync).

解决方案

I'm the author of that API.

chrome.storage.local shouldn't be disappearing except on uninstallation (which sounds like is your case) or, very rarely, on database corruption (and we've seen this particularly happening on System Restore).

chrome.storage.sync works the same way, except that the merge algorithm it uses may cause data loss if 2 machines make conflicting changes. In your case, this might happen if you sign into the machine which is using chrome.storage.sync. More commonly it will be because one machine is offline while making the change, or perhaps the user managed to simultaneously change data on 2 machines (which is why it's recommended to only change data on user action -- we should document that).

For what it's worth -- and we should document this too -- the merge algorithm is last-change-wins and sync-is-source-of-truth -- but any local key/value pairs added won't be deleted. If you have:

{a:1, b:2} on computer A (signed in and syncing), {b:3, c:4} on computer B (not signed in),

and computer B signs in, after doing a full sync the state of storage on both A and B will end up at {a:1, b:2, c:4} because A's data was already part of sync, this the source of truth, but 'c' didn't exist yet so was added.

In this scenario A will have gotten an onChange event adding 'c', and B will have gotten an onChange event adding 'a' and updating 'b' from 3 to 2.

这篇关于Chrome.Storage.Local持久性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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