Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CacheList#match - make cache name optional? #117

Closed
jakearchibald opened this issue Nov 1, 2013 · 5 comments
Closed

CacheList#match - make cache name optional? #117

jakearchibald opened this issue Nov 1, 2013 · 5 comments

Comments

@jakearchibald
Copy link
Contributor

Storing stuff in multiple caches is great, but leads to fetches like…

this.onfetch = function(event) {
  event.respondWith(
    caches.match('whatever', event.request.url).catch(function() {
      return caches.match('somethingElse', event.request.url);
    }).catch(function() {
      return caches.match('foobar', event.request.url);
    }).catch(function() {
      return fetch(event.request);
    })
  );
};

…as we search through caches for one with a match. It's possible, but unlikely to have two caches containing the same url. It'd be nice to swap the params of match around and make the cache name optional.

this.onfetch = function(event) {
  event.respondWith(
    caches.match(event.request.url).catch(function() {
      return fetch(event.request);
    })
  );
};

Much shorter. If the url exists in two caches, just return one of them.

@annevk
Copy link
Member

annevk commented Nov 1, 2013

If we do this, please do define in detail which resource is returned in case of a duplicate match.

@jakearchibald
Copy link
Contributor Author

Well, querySelector returns the first match, so match could return the first cached item?

@annevk
Copy link
Member

annevk commented Nov 1, 2013

Sure, but that means you have to define how the caches are ordered relative to each other.

@jakearchibald
Copy link
Contributor Author

What order do items iterate in a map? Could use that.
On 2 Nov 2013 00:28, "Anne van Kesteren" notifications@github.com wrote:

Sure, but that means you have to define how the caches are ordered
relative to each other.


Reply to this email directly or view it on GitHubhttps://github.com//issues/117#issuecomment-27573731
.

@tabatkins
Copy link
Member

Maps are iterated in insertion order. As long as these are always author-defined, we're fine. Can they ever get created by the browser?

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

No branches or pull requests

4 participants