From ff2bdfd37fa6c0dfc77a287dd00d564f854cb22e Mon Sep 17 00:00:00 2001 From: Gregor Noczinski Date: Wed, 20 Dec 2023 15:00:42 +0100 Subject: [PATCH] Improve caching timeouts --- package.json | 2 +- src/packages.ts | 4 ++-- src/packages_github.ts | 2 +- wrangler.toml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d931698..5109905 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "start": "wrangler dev --test-scheduled", "build": "wrangler deploy --dry-run --outdir=dist", - "deploy": "wrangler deploy --env production", + "deploy": "wrangler deploy", "login": "wrangler login", "lint": "eslint src --ext js,ts,mts --max-warnings 0 && prettier --check .", "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js", diff --git a/src/packages.ts b/src/packages.ts index dd14b29..a730aa6 100644 --- a/src/packages.ts +++ b/src/packages.ts @@ -50,7 +50,7 @@ export class CompoundPackages implements Packages { public async findHelmIndex(request: Request, env: Environment): Promise { let content: ReadableStream | string | null = await env.KV.get(helmIndexKey, { type: 'stream', - cacheTtl: oneDayInSeconds, + cacheTtl: oneMinuteInSeconds, }); if (!content) { @@ -63,7 +63,7 @@ export class CompoundPackages implements Packages { status: 200, headers: { 'Content-Type': 'text/yaml', - 'Cache-Control': `public, max-age=${oneMinuteInSeconds * 5}, immutable`, + 'Cache-Control': `public, max-age=${oneMinuteInSeconds * 5}, public`, }, }; diff --git a/src/packages_github.ts b/src/packages_github.ts index d1885f5..a50b4d7 100644 --- a/src/packages_github.ts +++ b/src/packages_github.ts @@ -76,7 +76,7 @@ export class GitHubPackages { // Reconstruct the Response object to make its headers mutable. const toCacheResponse = new Response(fetchedResponse.body, response); toCacheResponse.headers.set('X-Snapshot', `${snapshot}`); - toCacheResponse.headers.set('Cache-Control', `public, max-age=${fetchedResponse.status >= 400 ? ttlNotFound : ttl}, immutable`); + toCacheResponse.headers.set('Cache-Control', `public, max-age=${fetchedResponse.status >= 400 ? ttlNotFound : ttl}, public`); await cache.put(cacheKey, toCacheResponse); console.info(`Cache missed, need to retrieve it: ${this.organization}/${repository}/${file}... DONE (exists: ${fetchedResponse.status < 400})!`); diff --git a/wrangler.toml b/wrangler.toml index 2baf407..461f601 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -13,4 +13,4 @@ node_compat = true GITHUB_ACCESS_USER = "echocatbot" [triggers] -crons = [ "0 */2 * * *" ] +crons = [ "0 * * * *" ]