mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Improve cache parformance
This commit is contained in:
parent
72245888de
commit
20908aff97
2 changed files with 14 additions and 4 deletions
14
api/index.ts
14
api/index.ts
|
|
@ -13,10 +13,18 @@ import { cacheProvider } from "../src/config/cache.ts";
|
|||
const serviceProvider = new GithubApiService();
|
||||
const client = new GithubRepositoryService(serviceProvider).repository;
|
||||
|
||||
// Build cache control header with optimized caching strategy
|
||||
const cacheControlHeader = [
|
||||
"public",
|
||||
`max-age=${CONSTANTS.CACHE_MAX_AGE}`,
|
||||
`s-maxage=${CONSTANTS.CDN_CACHE_MAX_AGE}`,
|
||||
`stale-while-revalidate=${CONSTANTS.STALE_WHILE_REVALIDATE}`,
|
||||
].join(", ");
|
||||
|
||||
const defaultHeaders = new Headers(
|
||||
{
|
||||
"Content-Type": "image/svg+xml",
|
||||
"Cache-Control": `public, max-age=${CONSTANTS.CACHE_MAX_AGE}`,
|
||||
"Cache-Control": cacheControlHeader,
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -86,7 +94,7 @@ async function app(req: Request): Promise<Response> {
|
|||
status: error.status,
|
||||
headers: new Headers({
|
||||
"Content-Type": "text",
|
||||
"Cache-Control": `public, max-age=${CONSTANTS.CACHE_MAX_AGE}`,
|
||||
"Cache-Control": cacheControlHeader,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
|
@ -132,7 +140,7 @@ async function app(req: Request): Promise<Response> {
|
|||
status: userResponseInfo.code,
|
||||
headers: new Headers({
|
||||
"Content-Type": "text",
|
||||
"Cache-Control": `public, max-age=${CONSTANTS.CACHE_MAX_AGE}`,
|
||||
"Cache-Control": cacheControlHeader,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ const HOUR_IN_MILLISECONDS = 60 * 60 * 1000;
|
|||
|
||||
export const CONSTANTS = {
|
||||
CACHE_MAX_AGE: 18800,
|
||||
CDN_CACHE_MAX_AGE: 28800, // 8 hours for CDN edge cache
|
||||
STALE_WHILE_REVALIDATE: 86400, // 24 hours - serve stale while revalidating
|
||||
DEFAULT_PANEL_SIZE: 110,
|
||||
DEFAULT_MAX_COLUMN: 8,
|
||||
DEFAULT_MAX_ROW: 3,
|
||||
|
|
@ -60,7 +62,7 @@ export const CONSTANTS = {
|
|||
DEFAULT_NO_BACKGROUND: false,
|
||||
DEFAULT_NO_FRAME: false,
|
||||
DEFAULT_GITHUB_API: "https://api.github.com/graphql",
|
||||
DEFAULT_GITHUB_RETRY_DELAY: 1000,
|
||||
DEFAULT_GITHUB_RETRY_DELAY: 500,
|
||||
REVALIDATE_TIME: HOUR_IN_MILLISECONDS,
|
||||
REDIS_TTL: HOUR_IN_MILLISECONDS * 4,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue