Skip to content

Commit

Permalink
Improve caching timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
blaubaer committed Dec 20, 2023
1 parent 1e923dd commit ff2bdfd
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class CompoundPackages implements Packages {
public async findHelmIndex(request: Request, env: Environment): Promise<Response | undefined> {
let content: ReadableStream<any> | string | null = await env.KV.get(helmIndexKey, {
type: 'stream',
cacheTtl: oneDayInSeconds,
cacheTtl: oneMinuteInSeconds,
});

if (!content) {
Expand All @@ -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`,
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/packages_github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})!`);
Expand Down
2 changes: 1 addition & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ node_compat = true
GITHUB_ACCESS_USER = "echocatbot"

[triggers]
crons = [ "0 */2 * * *" ]
crons = [ "0 * * * *" ]

0 comments on commit ff2bdfd

Please sign in to comment.