2

I'm using the JS CacheStorage API, I need to make sure that the cached request is up to date. How can I retrieve the cached time of the saved cache?

Rivka
  • 171
  • 1
  • 6

2 Answers2

2

In your cache object, you can simply store the Date.now.

Note: I would post it as a comment but I don't have the reputation for that.

Yousuf Khan
  • 334
  • 3
  • 12
  • it's still not clear how to add data to response when It cached – Rivka Aug 14 '19 at 05:23
  • 1
    To add data to a response before caching, you must reconstruct the response as seen in this answer: https://stackoverflow.com/a/35421180/5500690 – derpedy-doo Nov 14 '19 at 19:24
0

I cache the entire app all at once whenever a semver version changes. At the end of the caching sequence, this code fires to create a request for /time-cached which I present on my dashboard for debugging purposes.

const cache = await caches.open(theVersion);
await cache.put('/time-cached', new Response( new Date() ));
Ninjaxor
  • 876
  • 12
  • 27