Skip to content
This repository was archived by the owner on May 30, 2025. It is now read-only.

Commit f2560f2

Browse files
authored
feat: large object cache (#220)
1 parent 82b9013 commit f2560f2

File tree

23 files changed

+199
-238
lines changed

23 files changed

+199
-238
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [0.46.0-pre.0](https://github.com/superfly/fly/compare/v0.45.2...v0.46.0-pre.0) (2019-03-07)
7+
8+
**Note:** Version bump only for package fly-root
9+
10+
11+
12+
13+
614
## [0.45.2](https://github.com/superfly/fly/compare/v0.45.1...v0.45.2) (2019-03-04)
715

816
**Note:** Version bump only for package fly-root

tests/apps/volatile-file-cache.js renamed to examples/volatile-file-cache/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
fly.http.respondWith(async req => {
22
const url = new URL(req.url)
33
const pathAndSearch = `${url.pathname}${url.search}`
4-
const key = pathAndSearch
54

6-
const cachedResp = await fetch(`storage://${key}`)
5+
const cachedResp = await fetch(`cache://${pathAndSearch}`)
76
if (cachedResp.ok) {
87
const headers = cachedResp.headers
98
headers.set("fly-cache", "hit")
@@ -13,9 +12,9 @@ fly.http.respondWith(async req => {
1312
const originResp = await fetch(`https://picsum.photos${pathAndSearch}`)
1413
const [respBody, cacheBody] = originResp.body.tee()
1514
if (originResp.ok) {
16-
fetch(`storage://${key}`, { body: cacheBody, method: "PUT", headers: originResp.headers })
17-
.then(ok => console.log(`cached ${key}`))
18-
.catch(err => console.warn(`failed to cache ${key}: ${e}`))
15+
fetch(`cache://${pathAndSearch}`, { body: cacheBody, method: "PUT", headers: originResp.headers })
16+
.then(ok => console.log(`cached ${pathAndSearch}`))
17+
.catch(err => console.warn(`failed to cache ${pathAndSearch}: ${e}`))
1918

2019
const headers = originResp.headers
2120
headers.set("fly-cache", "miss")

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"packages/*",
44
"tests/*"
55
],
6-
"version": "0.45.2",
6+
"version": "0.46.0-pre.0",
77
"npmClient": "yarn",
88
"useWorkspaces": true,
99
"command": {

packages/core/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [0.46.0-pre.0](https://github.com/superfly/fly/compare/v0.45.2...v0.46.0-pre.0) (2019-03-07)
7+
8+
**Note:** Version bump only for package @fly/core
9+
10+
11+
12+
13+
614
## [0.45.2](https://github.com/superfly/fly/compare/v0.45.1...v0.45.2) (2019-03-04)
715

816
**Note:** Version bump only for package @fly/core

packages/core/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fly/core",
3-
"version": "0.45.2",
3+
"version": "0.46.0-pre.0",
44
"license": "Apache-2.0",
55
"repository": {
66
"type": "git",
@@ -21,7 +21,6 @@
2121
"@fly/examples": "0.45.0",
2222
"@fly/v8env": "0.45.1",
2323
"ansi-colors": "^1.1.0",
24-
"aws-sdk": "^2.407.0",
2524
"axios": "^0.18.0",
2625
"better-sqlite3": "^4.1.4",
2726
"bluebird": "^3.5.1",

packages/core/src/bridge/fetch.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Runtime } from "../runtime"
1212
import { streamManager } from "../stream_manager"
1313
import { isNumber } from "util"
1414
import { setTimeout } from "timers"
15-
import { handleStorageRequest } from "./fetch/storage"
15+
import * as cacheHandler from "./fetch/cache"
1616

1717
const connectionStats = {
1818
created: 0,
@@ -146,9 +146,9 @@ registerBridge("fetch", function fetchBridge(
146146
return
147147
}
148148

149-
// if (u.protocol === "storage:") {
150-
// return handleStorageRequest(rt, bridge, u, init, body, cb)
151-
// }
149+
if (u.protocol === cacheHandler.scheme) {
150+
return cacheHandler.handleRequest(rt, bridge, u, init, body, cb)
151+
}
152152

153153
const httpFn = u.protocol === "http:" ? http.request : https.request
154154
const httpAgent = u.protocol === "http:" ? fetchAgent : fetchHttpsAgent

packages/core/src/bridge/fetch/storage.ts renamed to packages/core/src/bridge/fetch/cache.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { Readable } from "stream"
99
import { bufferToStream } from "../../utils/buffer"
1010
import { OutgoingHttpHeaders } from "http"
1111

12-
const scheme = "storage:"
12+
export const scheme = "cache:"
1313

14-
export function handleStorageRequest(
14+
export function handleRequest(
1515
rt: Runtime,
1616
bridge: Bridge,
1717
url: UrlWithStringQuery,
@@ -24,6 +24,7 @@ export function handleStorageRequest(
2424
return
2525
}
2626

27+
const ns = rt.app.id.toString()
2728
const key = url.href!.substring(scheme.length + 2)
2829

2930
if (!key || key === "/") {
@@ -32,8 +33,10 @@ export function handleStorageRequest(
3233
}
3334

3435
if (init.method === "GET") {
36+
log.debug("[blobcache] get", { key })
37+
3538
bridge.blobStore
36-
.get(rt.app.id, key)
39+
.get(ns, key)
3740
.then(res => {
3841
const id = streamManager.add(rt, res.stream)
3942
cb.applyIgnored(null, [
@@ -43,6 +46,7 @@ export function handleStorageRequest(
4346
])
4447
})
4548
.catch(err => {
49+
log.error("blobstore adapter error", err)
4650
let res
4751
if (err instanceof KeyNotFound) {
4852
res = makeResponse(404, "Not Found", url)
@@ -59,6 +63,8 @@ export function handleStorageRequest(
5963
])
6064
})
6165
} else if (init.method === "PUT") {
66+
log.debug("[blobcache] put", { key })
67+
6268
if (body === null) {
6369
cb.applyIgnored(null, [null, makeResponse(422, "Body is required", url)])
6470
return
@@ -69,7 +75,7 @@ export function handleStorageRequest(
6975
const headers = extractHeaders(init.headers || {})
7076

7177
bridge.blobStore
72-
.set(rt.app.id, key, bodyBuf, { headers })
78+
.set(ns, key, bodyBuf, { headers })
7379
.then(() => {
7480
cb.applyIgnored(null, [
7581
null,
@@ -87,8 +93,10 @@ export function handleStorageRequest(
8793
])
8894
})
8995
} else if (init.method === "DELETE") {
96+
log.debug("[blobcache] delete", { key })
97+
9098
bridge.blobStore
91-
.del(rt.app.id, key)
99+
.del(ns, key)
92100
.then(() => {
93101
cb.applyIgnored(null, [
94102
null,

packages/core/src/s3_blob_store.ts

Lines changed: 0 additions & 130 deletions
This file was deleted.

packages/fly/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [0.46.0-pre.0](https://github.com/superfly/fly/compare/v0.45.2...v0.46.0-pre.0) (2019-03-07)
7+
8+
**Note:** Version bump only for package @fly/fly
9+
10+
11+
12+
13+
614
## [0.45.2](https://github.com/superfly/fly/compare/v0.45.1...v0.45.2) (2019-03-04)
715

816
**Note:** Version bump only for package @fly/fly

packages/fly/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fly/fly",
3-
"version": "0.45.2",
3+
"version": "0.46.0-pre.0",
44
"description": "Open source Edge Application runtime",
55
"license": "Apache-2.0",
66
"repository": {
@@ -20,7 +20,7 @@
2020
"prepublishOnly": "yarn build"
2121
},
2222
"dependencies": {
23-
"@fly/core": "0.45.2",
23+
"@fly/core": "0.46.0-pre.0",
2424
"@fly/v8env": "0.45.1"
2525
},
2626
"publishConfig": {

0 commit comments

Comments
 (0)