superfly / fly

Deploy app servers close to your users. Package your app as a Docker image, and launch it in 17 cities with one simple CLI.
https://fly.io
985 stars 48 forks source link

Volatile file cache API #214

Closed mrkurt closed 5 years ago

mrkurt commented 5 years ago

The in memory cache is great, but lots of apps need to cache much larger amounts of data.

I think the best way to do this is to expose another fetch URL protocol within isolates with an S3 like adapter for persisting files.

It needs to:

Stream handling is important. This should be fast:

fly.http.respondWith(async (req) => {
    let resp = await fetch("storage://big-file.mkv")
    return resp
});

Likewise, so should this:

fly.http.respondWith(async (req) => {
    let resp = await fetch("https://origin.example.com/big-file.mkv");
    await fetch("storage://big-file.mkv", { method: "PUT" });
    return new Response('file saved!');
});

Fetching an external URL only sends header data into the isolate, unless you read the body within app code. This should work the same.