Rivka
Rivka

Reputation: 171

CacheStorage - How to retrieve the time cached of a request

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?

Upvotes: 2

Views: 2372

Answers (2)

Ninjaxor
Ninjaxor

Reputation: 998

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() ));

Upvotes: 0

Yousuf Khan
Yousuf Khan

Reputation: 334

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.

Upvotes: 2

Related Questions