tgvashworth / ServiceWorker-Polyfill

[DEPRECATED] JavaScript ServiceWorker implementation, enabling exploration by authors.
66 stars 7 forks source link

Persist caches #19

Closed jakearchibald closed 10 years ago

jakearchibald commented 10 years ago

…put them somewhere smarter. Probably just a directory.

Need to make sure they're cleaned up or reused when serviceworker restarts.

tgvashworth commented 10 years ago

My proposal is to put them in a LevelDB – x-platform and very Node-y.

jakearchibald commented 10 years ago

Cool. If the caches can't be explored on disk it'd be great to have a url to inspect them (future idea, of course).

Actually, since there's programmatic cache access, this could be written as a separate project, built with a ServiceWorker. On 9 Jan 2014 12:20, "Tom Ashworth" notifications@github.com wrote:

My proposal is to put them in a LevelDB – x-platform and very Node-y.

— Reply to this email directly or view it on GitHubhttps://github.com/phuu/serviceworker-demo/issues/19#issuecomment-31925613 .

tgvashworth commented 10 years ago

So, more thinking about this:

http-google-com.json
[
  {
    "name": "shell-v2",
    "items": {
      "some-url": { ... }
    }
  },
  { "name": "contents-v2", "items": { ... } },
  ...
]
tgvashworth commented 10 years ago

More thinking, new data structure schema:

/*

caches/
    origin/
        cache-xyz789.json
        bodies/
            body-123abc.json

*/

// cache-xyz789.json
{
    items: [{
        state: 'pending/fulfilled/rejected',
        request: { ... },
        resonse: {
            ... ,
            body: 'body-123abc'
        }
    }]
}

// body-123abc.json
{
    body: [123, 456, 789]
}

/*

cache-lists/
    some-origin.json

 */

// some-origin.json
{
    caches: [{
        name: 'app-cache',
        id: 'cache-xyz789'
    }]
}
jakearchibald commented 10 years ago

For the sake of the polyfill, garbage collecting caches when the worker is shut down is fine

tgvashworth commented 10 years ago