Re: [ServiceWorker] Can caches store and retrieve results that are still being written to the cache? (#573)

@jungkees 

I might be reading wrong, but I think there's been a couple of regressions in the spec. Imagine a cache with 2 entries that look like this header-wise (assume each has the same URL):

1. Request: `{ "Accept": "text/html" }` Response: `{"Vary": "Accept"}`
1. Request: `{ "Accept": "foo/bar" }` Response: `{}`

Then if we add a new entry to the cache, Request: `{ "Accept": "text/html" }` Response: `{}` (no Vary), the cache should now look like this:

1. Request: `{ "Accept": "text/html" }` Response: `{}`

The original algorithm would delete entries from the cache that match the new entry's request. As far as I can tell, the current spec would modify the first entry in the cache, leaving the second. That means the second entry cannot be matched, since the first will always match first. Am I reading it correctly?

In a system where we allow in-flight requests into the cache, it could work like this:

1. Request: `{ "Accept": "text/html" }` Response: `{"Vary": "Accept"}`
1. Request: `{ "Accept": "foo/bar" }` Response: `{}`

Then if we add a new entry to the cache, Request: `{ "Accept": "text/html" }` Response: `{}`:

1. Request: `{ "Accept": "text/html" }` Response: `{"Vary": "Accept"}`
1. Request: `{ "Accept": "foo/bar" }` Response: `{}`
1. Request: `{ "Accept": "text/html" }` Response: `{}` (in-flight)

So nothing's deleted from the cache at this stage. `.match` will favour entry 1 before 3, because it goes with first match. But once the request from entry 3 completes, it removes entries from the cache that match its request, leaving: 

1. Request: `{ "Accept": "text/html" }` Response: `{}`

This mean there aren't entries in the cache that cannot be matched.

I also think it's important to keep the cache in an order where the most recently added entries are at the end. This is useful when pruning caches. Talking to Twitter last week, they were interested in adding cached items back into the cache once they'd sent them to the browser. If added entries appear at the end of the list, this helps them track which items were "last accessed", therefore which entries they should keep.

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/573#issuecomment-70095338

Received on Thursday, 15 January 2015 14:47:42 UTC