How to cache storage in web extensions?

17 Views Asked by At

I am working on a web extension that uses browser.webRequest.onHeadersReceived() to call a function on every request. The function also needs to access some settings which I get from browser.storage.local.

Currently I fetch those settings on every request. However, requests usually come in bursts when all the data for a new page is loaded. During those bursts, the settings don't change, so it is really not necessary to fetches a fresh copy every time. To minimize the performance impact of my extension I would like to have some kind of cache.

Are there any established approaches for caching data across event handlers in web extensions? The official docs explicitly warn not to use global variables and to always use browser.storage instead. Or is browser.storage fast enough to fetch the same data a few hundred times per second without a significant impact?

0

There are 0 best solutions below