Skip to content

Commit 2472140

Browse files
committed
feat: cache-control headers to let cloudflare be able to cache more
1 parent 381059c commit 2472140

8 files changed

Lines changed: 229 additions & 20 deletions

File tree

server/db/updateModals.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { mainDb } from './connection.js';
22
import { sql } from 'kysely';
33
import { redisConnection } from './connection.js';
4+
import { UPDATE_MODAL_REDIS_SEC } from '../utils/cacheTtl.js';
45

56
const ACTIVE_MODAL_CACHE_KEY = 'update_modal:active';
67

@@ -28,7 +29,7 @@ export async function getActiveUpdateModal() {
2829
ACTIVE_MODAL_CACHE_KEY,
2930
JSON.stringify(result),
3031
'EX',
31-
24 * 60 * 60
32+
UPDATE_MODAL_REDIS_SEC
3233
);
3334
} catch (error) {
3435
console.warn('[Redis] Failed to cache active modal:', error);

server/db/version.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { mainDb } from './connection.js';
2+
import { APP_VERSION_REDIS_SEC } from '../utils/cacheTtl.js';
23

34
export async function getAppVersion() {
45
const result = await mainDb
@@ -27,7 +28,12 @@ export async function getAppVersion() {
2728

2829
try {
2930
const { redisConnection } = await import('./connection.js');
30-
await redisConnection.set('app:version', JSON.stringify(defaultVersion));
31+
await redisConnection.set(
32+
'app:version',
33+
JSON.stringify(defaultVersion),
34+
'EX',
35+
APP_VERSION_REDIS_SEC
36+
);
3137
} catch (error) {
3238
console.warn('[Redis] Failed to set version cache:', error);
3339
}
@@ -42,7 +48,12 @@ export async function getAppVersion() {
4248

4349
try {
4450
const { redisConnection } = await import('./connection.js');
45-
await redisConnection.set('app:version', JSON.stringify(versionData));
51+
await redisConnection.set(
52+
'app:version',
53+
JSON.stringify(versionData),
54+
'EX',
55+
APP_VERSION_REDIS_SEC
56+
);
4657
} catch (error) {
4758
console.warn('[Redis] Failed to set version cache:', error);
4859
}

server/routes/admin/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { requirePermission } from '../../middleware/rolePermissions.js';
55
import { getDailyStatistics, getTotalStatistics } from '../../db/admin.js';
66
import { getAppVersion, updateAppVersion } from '../../db/version.js';
77
import { redisConnection } from '../../db/connection.js';
8+
import { APP_VERSION_REDIS_SEC } from '../../utils/cacheTtl.js';
89

910
import usersRouter from './users.js';
1011
import sessionsRouter from './sessions.js';
@@ -107,7 +108,7 @@ router.put(
107108
cacheKey,
108109
JSON.stringify(updatedVersion),
109110
'EX',
110-
86400
111+
APP_VERSION_REDIS_SEC
111112
);
112113
} catch (error) {
113114
if (error instanceof Error) {

0 commit comments

Comments
 (0)