Javascript 开发Chrome扩展时如何清除`chrome.storage.local`缓存?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31812937/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 07:13:29  来源:igfitidea点击:

How to clear `chrome.storage.local` cache when developing a Chrome Extension?

javascriptgoogle-chromecachinggoogle-chrome-extension

提问by bodacydo

I've written a Chrome Extension for my library. It uses chrome.storage.localto cache things.

我为我的图书馆编写了一个 Chrome 扩展程序。它chrome.storage.local用来缓存东西。

Does anyone know how to drop the cache for testing purposes? I can't really test things anymore as all the data is now in cache. I'd like to drop it and make sure it gets repopulated correctly, etc. How do I do that?

有谁知道如何删除缓存以进行测试?由于所有数据现在都在缓存中,因此我无法再测试了。我想删除它并确保它正确地重新填充,等等。我该怎么做?

I tried "Refresh"-ing the extension but that did nothing. Removing and adding the extension doesn't appear to clean cache either.

我尝试了“刷新”扩展名,但没有任何作用。删除和添加扩展似乎也不会清理缓存。

回答by wOxxOm

Use chrome.storage.local.clear()

使用chrome.storage.local.clear()

To check the status use a callback (optional):

要检查状态使用回调(可选):

chrome.storage.local.clear(function() {
    var error = chrome.runtime.lastError;
    if (error) {
        console.error(error);
    }
});

回答by Satish Kumar sonker

You can also use chrome.storage.local.remove()method if you want to remove any specific or list of specific object from Storage

如果要从 Storage 中删除任何特定对象或特定对象列表,也可以使用chrome.storage.local.remove()方法

chrome.storage.local.remove(["Key1","key2"],function(){
 var error = chrome.runtime.lastError;
    if (error) {
        console.error(error);
    }
})

回答by Hp Sharma

Check this out

看一下这个

chrome.storage.local.remove(keyName,function() {
 // Your code
 // This is an asyn function
});

Check full details https://developer.chrome.com/extensions/storage

检查完整详细信息https://developer.chrome.com/extensions/storage