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

Persist caches #19

Closed
jakearchibald opened this issue Jan 7, 2014 · 6 comments · May be fixed by #53
Closed

Persist caches #19

jakearchibald opened this issue Jan 7, 2014 · 6 comments · May be fixed by #53
Assignees
Labels

Comments

@jakearchibald
Copy link
Collaborator

…put them somewhere smarter. Probably just a directory.

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

@tgvashworth
Copy link
Owner

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

@jakearchibald
Copy link
Collaborator Author

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//issues/19#issuecomment-31925613
.

@ghost ghost assigned tgvashworth Jan 9, 2014
@tgvashworth
Copy link
Owner

So, more thinking about this:

  • LevelDB is over-complicating it. All Responses are JSON stringifyable, so they should go in files
  • This is also easier to debug
  • Caches are grouped by domain, so I suggest using a file named by domain:
http-google-com.json
[
  {
    "name": "shell-v2",
    "items": {
      "some-url": { ... }
    }
  },
  { "name": "contents-v2", "items": { ... } },
  ...
]
  • The Cache should return a Promise for writing to this file
  • What does it mean to ask Cache#has? Only if definitely written.
  • Cache order is important
  • Maybe use promised-io

@tgvashworth
Copy link
Owner

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
Copy link
Collaborator Author

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

@tgvashworth
Copy link
Owner

  • persist all Caches to a cache heap
  • bodies also go on heap
  • when Cache is set to CacheList, point the CacheList to that cache

tgvashworth pushed a commit that referenced this issue Jan 19, 2014
WIP
Fix #19.
@tgvashworth tgvashworth mentioned this issue Jan 19, 2014
3 tasks
tgvashworth pushed a commit that referenced this issue Jan 19, 2014
WIP
Fix #19.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants