You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're using the storage to cache the release count and the users' full name. These caches don't expire and they just pile up. There should be a mechanism to either regularly purge the cache or to make them expire.
A thought was to use good ol' cookies in the background.js (yes they work in there) since the expiration is handled natively and new items push out the old items once the limit is reached — just like you'd expect from a cache.
However cookies are limited to 4KB (instead of 5MB), which maybe fits around 100 user names and 40 release counts.
The proper way to do it while continuing to use a key-value cache would be to store the current timestamp + time to live in seconds in the value of the cache entry next to the actual value. On every read from the cache you will check if you need to invalidate it based on the current time and the calculated expired timestamp (saving original timestamp + time to live instead of just timestamp to expire is crucial for future changes so you can distinguish young vs. old caches).
Then on every X days or Nth reads, you will iterate over all caches and invalidate the ones which need to be invalidated. This way you're conserving storage and invalidating caches which won't be read otherwise.
Sounds like a request for a package.
I'm fine with purging everything every X days, but thought I'll just leave my suggestion here if anyone wants to implement a package for caching in browser extensions :)
@hkdobrev I considered a TTL too, but I just don't see it being worth the complication. The optimal solution would be to use an LRU store, so we expunge the least recently used items for optimal efficiency. But I still think the naive approach is ok.
Activity
sindresorhus commentedon Jul 18, 2017
I would just go the easy route and purge the cache every x days (100?).
hkdobrev commentedon Jul 18, 2017
The proper way to do it while continuing to use a key-value cache would be to store the current timestamp + time to live in seconds in the value of the cache entry next to the actual value. On every read from the cache you will check if you need to invalidate it based on the current time and the calculated expired timestamp (saving original timestamp + time to live instead of just timestamp to expire is crucial for future changes so you can distinguish young vs. old caches).
Then on every X days or Nth reads, you will iterate over all caches and invalidate the ones which need to be invalidated. This way you're conserving storage and invalidating caches which won't be read otherwise.
Sounds like a request for a package.
I'm fine with purging everything every X days, but thought I'll just leave my suggestion here if anyone wants to implement a package for caching in browser extensions :)
sindresorhus commentedon Jul 18, 2017
@hkdobrev I considered a TTL too, but I just don't see it being worth the complication. The optimal solution would be to use an LRU store, so we expunge the least recently used items for optimal efficiency. But I still think the naive approach is ok.
fregante commentedon Jul 28, 2017
@sindresorhus we'd have to use another solution though because
browser.storagedoesn't support Mapsindresorhus commentedon Jul 28, 2017
We could create a wrapper, like https://github.com/sindresorhus/refined-github/blob/master/src/libs/synchronous-storage.js
fregante commentedon Dec 8, 2017
I vote for clearing every 15 days.
Done. Less code, probably more efficient. We just have to avoid dropping the
unreadNotificationssindresorhus commentedon Dec 8, 2017
Make it every 30 days and I'm 👍