Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Have ready() and add() resolve with added responses

  • Loading branch information...
commit e7b12e790d49624c1d58152792a4fe7eb5c206b9 1 parent ca47978
@jakearchibald jakearchibald authored
Showing with 13 additions and 2 deletions.
  1. +10 −1 service_worker.js
  2. +3 −1 service_worker.ts
View
11 service_worker.js
@@ -378,7 +378,7 @@ var FetchEvent = (function (_super) {
// Design notes:
// - Caches are atomic: they are not complete until all of their resources are
-// fetched.
+// fetched
// - Updates are also atomic: the old contents are visible until all new
// contents are fetched/installed.
// - Caches should have version numbers and "update" should set/replace it
@@ -405,6 +405,9 @@ var Cache = (function () {
// This needs to reject to work well with respondWith
};
+ // TODO: maybe this would be better as a querying method
+ // so matchAll(string) would match all entries for that
+ // url regardless of method & vary
Cache.prototype.matchAll = function (request) {
var thisCache = this;
@@ -443,6 +446,10 @@ var Cache = (function () {
for (var i = 0; i < varyHeaders.length; i++) {
varyHeader = varyHeaders[i].trim();
+ if (varyHeader == '*') {
+ continue;
+ }
+
if (cachedRequest.headers.get(varyHeader) != filterRequest.headers.get(varyHeader)) {
return false;
}
@@ -510,6 +517,8 @@ var Cache = (function () {
// Deleting is garbage collection, but also ensures "uniqueness"
return this.delete(request).then(function () {
return thisCache._items.set(request, response);
+ }).then(function () {
+ return response;
});
};
View
4 service_worker.ts
@@ -643,9 +643,11 @@ class Cache {
// TODO: this delete/set implementation isn't atomic, but needs to be.
// Not sure how to implement it, maybe via a private _locked promise?
- // Deleting is garbage collection, but also ensures "uniqueness"
+ // Deleting is garbage collection, but also ensures "uniqueness"
return this.delete(request).then(function() {
return thisCache._items.set(request, response);
+ }).then(function() {
+ return response;
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.