service worker CacheAPI use `Time Cached` attribute with cache.matchAll

603 views Asked by At

I am caching some data like thumbnails and also JSON in our web app. Now I want to delete old data when I reach the disk space.

Chrome shows in his web tools (not perfectly, it doesn't show the correct time for self-created responses) the attribute Time Cached in the Cache Storage.

So this data must be somewhere and I want to use it.

My plan would be to do work with cache.matchAll and sort the result by the Time Cached attribute to delete the oldest one.

But match All just returns normal Responses, where I don't have Time Cached.

1

There are 1 answers

0
jsaddwater On

Actually CacheAPI stores the new response over the old one,if the request URL is the same, so when you cache.match(event.request) you always get the newest (and only one). Also, in my case the response has a 'date' header, which you can compare against the current date and find out if you need to fetch from network or notenter image description here