Skip to content

Instantly share code, notes, and snippets.

@jonchenn
Created February 1, 2019 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonchenn/255278f60a9f2fa8da9335061ca1a010 to your computer and use it in GitHub Desktop.
Save jonchenn/255278f60a9f2fa8da9335061ca1a010 to your computer and use it in GitHub Desktop.
data = await idbKeyval.get(id, store);
if (!data) return null;
// Check cache max age.
let cacheControl = request.headers.get('Cache-Control');
let maxAge = cacheControl ? parseInt(cacheControl.split('=')[1]) : 3600;
if (Date.now() - data.timestamp > maxAge * 1000) {
return null; // Invalidate the cache data.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment