Skip to content

Instantly share code, notes, and snippets.

@adrianholovaty
Created December 27, 2015 14:06
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 adrianholovaty/0568c895fafd9417e13c to your computer and use it in GitHub Desktop.
Save adrianholovaty/0568c895fafd9417e13c to your computer and use it in GitHub Desktop.
Service worker cache wrapper that lets you use arbitrary cache keys
function cachePut(key, request, response) {
caches.open(key).then(function(cache) {
cache.put(request, response);
});
}
function cacheGet(key) {
return new Promise(function(resolve, reject) {
caches.open(key).then(function(cache) {
cache.keys().then(function(keyArray) {
if (keyArray.length) {
cache.match(keyArray[0]).then(function(response) {
resolve(response);
});
}
else {
resolve(null);
}
});
});
});
}
@adrianholovaty
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment