@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 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 always reads fresh.
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 { Body } = await s3.send(new client_s3_1.GetObjectCommand({ Bucket: BUCKET, Key: `${name}.zap` }));
11
- return Body.transformToString();
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kirkelliott/zap",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "description": "Drop a .zap file in S3. It becomes an API endpoint.",
5
5
  "main": "dist/handler.js",
6
6
  "bin": {