@kirkelliott/zap 0.1.23 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/handler.js +10 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -318,7 +318,7 @@ One Lambda function runs permanently. Every request:
|
|
|
318
318
|
4. Calls the exported function with the request
|
|
319
319
|
5. Returns the response
|
|
320
320
|
|
|
321
|
-
Updating a handler means updating a file in S3. The runtime
|
|
321
|
+
Updating a handler means updating a file in S3. The runtime caches source in Lambda memory for 5 seconds, then reads fresh. Deploys propagate within 5 seconds on warm containers.
|
|
322
322
|
|
|
323
323
|
---
|
|
324
324
|
|
package/dist/handler.js
CHANGED
|
@@ -6,9 +6,17 @@ const eval_1 = require("./eval");
|
|
|
6
6
|
const types_1 = require("./types");
|
|
7
7
|
const s3 = new client_s3_1.S3Client({});
|
|
8
8
|
const BUCKET = process.env.ZAP_BUCKET;
|
|
9
|
+
const TTL = 5_000;
|
|
10
|
+
const cache = new Map();
|
|
9
11
|
const loader = async (name) => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
+
const hit = cache.get(name);
|
|
13
|
+
if (hit && Date.now() - hit.at < TTL)
|
|
14
|
+
return hit.source;
|
|
15
|
+
const { Body, ETag, LastModified } = await s3.send(new client_s3_1.GetObjectCommand({ Bucket: BUCKET, Key: `${name}.zap` }));
|
|
16
|
+
const source = await Body.transformToString();
|
|
17
|
+
cache.set(name, { source, at: Date.now() });
|
|
18
|
+
console.log(JSON.stringify({ cache: 'refresh', handler: name, etag: ETag, modified: LastModified?.toISOString() }));
|
|
19
|
+
return source;
|
|
12
20
|
};
|
|
13
21
|
const handler = async (event, context) => {
|
|
14
22
|
const start = Date.now();
|