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

↘锁芯ラ 提交于 2020-01-22 13:12:05

问题


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

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.


回答1:


Use 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);
    }
});



回答2:


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

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



回答3:


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://stackoverflow.com/questions/31812937/how-to-clear-chrome-storage-local-cache-when-developing-a-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!